当前位置: 首页>>代码示例>>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;未经允许,请勿转载。