當前位置: 首頁>>代碼示例>>Python>>正文


Python pyplot.FuncFormatter方法代碼示例

本文整理匯總了Python中matplotlib.pyplot.FuncFormatter方法的典型用法代碼示例。如果您正苦於以下問題:Python pyplot.FuncFormatter方法的具體用法?Python pyplot.FuncFormatter怎麽用?Python pyplot.FuncFormatter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在matplotlib.pyplot的用法示例。


在下文中一共展示了pyplot.FuncFormatter方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_tick_label_update

# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import FuncFormatter [as 別名]
def test_tick_label_update():
    # test issue 9397

    fig, ax = plt.subplots()

    # Set up a dummy formatter
    def formatter_func(x, pos):
        return "unit value" if x == 1 else ""
    ax.xaxis.set_major_formatter(plt.FuncFormatter(formatter_func))

    # Force some of the x-axis ticks to be outside of the drawn range
    ax.set_xticks([-1, 0, 1, 2, 3])
    ax.set_xlim(-0.5, 2.5)

    ax.figure.canvas.draw()
    tick_texts = [tick.get_text() for tick in ax.xaxis.get_ticklabels()]
    assert tick_texts == ["", "", "unit value", "", ""] 
開發者ID:holzschu,項目名稱:python3_ios,代碼行數:19,代碼來源:test_axes.py

示例2: axes_stat

# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import FuncFormatter [as 別名]
def axes_stat(self, rect):
        """
        rect : sequence of float
               The dimensions [left, bottom, width, height] of the new axes. All
               quantities are in fractions of figure width and height.
        """
        # Enrichment score plot
        
        ax4 = self.fig.add_axes(rect)
        ax4.plot(self._x, self.RES, linewidth=4, color ='#88C544')
        ax4.text(.1, .1, self._fdr_label, transform=ax4.transAxes)
        ax4.text(.1, .2, self._pval_label, transform=ax4.transAxes)
        ax4.text(.1, .3, self._nes_label, transform=ax4.transAxes)

        # the y coords of this transformation are data, and the x coord are axes
        trans4 = transforms.blended_transform_factory(ax4.transAxes, ax4.transData)
        ax4.hlines(0, 0, 1, linewidth=.5, transform=trans4, color='grey')
        ax4.set_ylabel("Enrichment Score", fontsize=14)
        #ax4.set_xlim(min(self._x), max(self._x))
        ax4.tick_params(axis='both', which='both', 
                        bottom=False, top=False, right=False,
                        labelbottom=False)
        ax4.locator_params(axis='y', nbins=5)
        # FuncFormatter need two argument, I don't know why. this lambda function used to format yaxis tick labels.
        ax4.yaxis.set_major_formatter(
            plt.FuncFormatter(lambda tick_loc,tick_num :  '{:.1f}'.format(tick_loc)) )

        self.ax = ax4 
開發者ID:zqfang,項目名稱:GSEApy,代碼行數:30,代碼來源:plot.py

示例3: multi_curve_plot

# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import FuncFormatter [as 別名]
def multi_curve_plot(multi_df):
    xScale=multi_df.shape[0]
    fig, ax = plt.subplots(1, 1, figsize=(20, 10))
    ax.set_prop_cycle(color=[
        '#1f77b4', '#aec7e8', '#ff7f0e', '#ffbb78', '#2ca02c', '#98df8a',
        '#d62728', '#ff9896', '#9467bd', '#c5b0d5', '#8c564b', '#c49c94',
        '#e377c2', '#f7b6d2', '#7f7f7f', '#c7c7c7', '#bcbd22', '#dbdb8d',
        '#17becf', '#9edae5'])
    ax.spines['top'].set_visible(False)
    ax.spines['bottom'].set_visible(False)
    ax.spines['right'].set_visible(False)
    ax.spines['left'].set_visible(False)

    ax.get_xaxis().tick_bottom()
    ax.get_yaxis().tick_left()

    fig.subplots_adjust(left=.06, right=.75, bottom=.02, top=.94)
    ax.set_xlim(0,xScale+1)
    ax.set_ylim(-0.2, 0.6)
    ax.set_xticks(range(xScale))
    ax.set_yticks(np.arange(0,0.6,0.1))
    ax.xaxis.set_major_formatter(plt.FuncFormatter('{:.0f}'.format))
    ax.yaxis.set_major_formatter(plt.FuncFormatter('{:.2f}'.format))
    ax.grid(True, 'major', 'y', ls='--', lw=.5, c='k', alpha=.3)
    ax.tick_params(axis='both', which='both', labelsize=14,
                   bottom=False, top=False, labelbottom=True,
                   left=False, right=False, labelleft=True)
    majors = ["PHMI_chi2","PHMI_qdtN","PHMI_nQ"] 
    y_offsets = {
        "PHMI_chi2":-0.02,
        }
    for column in majors:
        line, = ax.plot(list(range(xScale)), column, data=multi_df,lw=2.5)
        y_pos =multi_df[column].to_list()[-1]    
        if column in y_offsets:
            y_pos += y_offsets[column]        
        ax.text(xScale-0.8, y_pos, column, fontsize=14, color=line.get_color())
        fig.suptitle("correlation data curve", fontsize=18, ha="left")
    plt.show()
# multi_curve_plot(multi_df) 
開發者ID:richieBao,項目名稱:python-urbanPlanning,代碼行數:42,代碼來源:driverlessCityProject_spatialPointsPattern_association_corr.py

示例4: axes_rank

# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import FuncFormatter [as 別名]
def axes_rank(self, rect):
        """
        rect : sequence of float
               The dimensions [left, bottom, width, height] of the new axes. All
               quantities are in fractions of figure width and height.
        """
        # Ranked Metric Scores Plot
        ax1 = self.fig.add_axes(rect, sharex=self.ax)
        if self.module == 'ssgsea':
            ax1.fill_between(self._x, y1=np.log(self.rankings), y2=0, color='#C9D3DB')
            ax1.set_ylabel("log ranked metric", fontsize=14)
        else:
            ax1.fill_between(self._x, y1=self.rankings, y2=0, color='#C9D3DB')
            ax1.set_ylabel("Ranked list metric", fontsize=14)

        ax1.text(.05, .9, self._pos_label, color='red',
                horizontalalignment='left', verticalalignment='top',
                transform=ax1.transAxes)
        ax1.text(.95, .05, self._neg_label, color='Blue',
                horizontalalignment='right', verticalalignment='bottom',
                transform=ax1.transAxes)
        # the x coords of this transformation are data, and the y coord are axes
        trans1 = transforms.blended_transform_factory(ax1.transData, ax1.transAxes)
        ax1.vlines(self._zero_score_ind, 0, 1, linewidth=.5, 
                    transform=trans1, linestyles='--', color='grey')

        hap = self._zero_score_ind / max(self._x) 
        if hap < 0.25:
            ha = 'left'
        elif hap > 0.75:
            ha = 'right'
        else:
            ha = 'center'  
        ax1.text(hap, 0.5, self._z_score_label,
                    horizontalalignment=ha,
                    verticalalignment='center',
                    transform=ax1.transAxes)
        ax1.set_xlabel("Rank in Ordered Dataset", fontsize=14)
        ax1.spines['top'].set_visible(False)
        ax1.tick_params(axis='both', which='both', top=False, right=False, left=False)
        ax1.locator_params(axis='y', nbins=5)
        ax1.yaxis.set_major_formatter(
            plt.FuncFormatter(lambda tick_loc,tick_num :  '{:.1f}'.format(tick_loc) )) 
開發者ID:zqfang,項目名稱:GSEApy,代碼行數:45,代碼來源:plot.py

示例5: plot_hist

# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import FuncFormatter [as 別名]
def plot_hist(self, ax, overlapping=False, formatted_yaxis=True, **kwargs):
        """Returns a matplotlib style histogram (matplotlib.pyplot.hist)

        Uses the matplotlib object oriented interface to add a Histogram to an matplotlib Axes object.
        All named arguments from pyplot.hist can be used. A new argument called "type" makes it possible to
        make overlapping histogram plots.

        Args:
            :ax: (`Axes`)
                An matplotlib Axes object on which the histogram will be plot
            :overlapping (`bool`, optional):
                If set to true, this will generate an overlapping plot.
                When set to False it will generate a normal grouped histogram. Defaults to False.
            :formatted_yaxis: (`bool`, optional).
                If set to true, the numbers on the yaxis will be formatted
                for better readability. E.g. 1500000 will become 1.5M. Defaults to True
            :**kwargs:
                The keyword arguments as used in matplotlib.pyplot.hist
        """
        self.build()

        if formatted_yaxis:
            # Round the y-axis value to nearest thousand, million, or billion for readable y-axis
            formatter = plt.FuncFormatter(Histogram._convert_number_bmk)
            ax.yaxis.set_major_formatter(formatter)

        if overlapping:
            for colname in self.hist_dict:
                ax.hist(self._get_bin_centers(),
                        bins=self.bin_boundaries,
                        alpha=0.5,
                        label=self.hist_dict.keys(),
                        weights=self.hist_dict[colname],
                        **kwargs
                        )
        else:
            weights_multi = [self.hist_dict[colname] for colname in self.hist_dict]
            return ax.hist([self._get_bin_centers()] * len(self.hist_dict),
                           bins=self.bin_boundaries,
                           weights=weights_multi,
                           label=self.hist_dict.keys(),
                           **kwargs) 
開發者ID:Bergvca,項目名稱:pyspark_dist_explore,代碼行數:44,代碼來源:pyspark_dist_explore.py

示例6: plot_hist

# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import FuncFormatter [as 別名]
def plot_hist(self, ax, overlapping=False, formatted_yaxis=True, **kwargs):
        """Returns a matplotlib style histogram (matplotlib.pyplot.hist)

        Uses the matplotlib object oriented interface to add a Histogram to an matplotlib Axes object.
        All named arguments from pyplot.hist can be used. A new argument called "type" makes it possible to
        make overlapping histogram plots.

        Args:
            :ax: (`Axes`)
                An matplotlib Axes object on which the histogram will be plot
            :overlapping (`bool`, optional):
                If set to true, this will generate an overlapping plot.
                When set to False it will generate a normal grouped histogram. Defaults to False.
            :formatted_yaxis: (`bool`, optional).
                If set to true, the numbers on the yaxis will be formatted
                for better readability. E.g. 1500000 will become 1.5M. Defaults to True
            :\*\*kwargs:
                The keyword arguments as used in matplotlib.pyplot.hist
        """
        self.build()

        if formatted_yaxis:
            # Round the y-axis value to nearest thousand, million, or billion for readable y-axis
            formatter = plt.FuncFormatter(Histogram._convert_number_bmk)
            ax.yaxis.set_major_formatter(formatter)

        if overlapping:
            for colname in self.hist_dict:
                ax.hist(self._get_bin_centers(),
                        bins=self.bin_list,
                        alpha=0.5,
                        label=self.hist_dict.keys(),
                        weights=self.hist_dict[colname],
                        **kwargs
                        )
        else:
            weights_multi = [self.hist_dict[colname] for colname in self.hist_dict]
            return ax.hist([self._get_bin_centers()] * len(self.hist_dict),
                           bins=self.bin_list,
                           weights=weights_multi,
                           label=self.hist_dict.keys(),
                           **kwargs) 
開發者ID:Bergvca,項目名稱:pyspark_dist_explore,代碼行數:44,代碼來源:pyspark_dist_explore.py


注:本文中的matplotlib.pyplot.FuncFormatter方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。