【问题标题】:How to increase the values size in a matplotlib colorbar如何增加 matplotlib 颜色栏中的值大小
【发布时间】:2014-02-06 17:41:09
【问题描述】:

我正在尝试增加颜色栏中的值大小。似乎微不足道,但我一直无法弄清楚。

我制作了一张热图,代码如下:

def heatmap_binary(df,
            edgecolors='w',
            cmap=mpl.cm.seismic, # spectral, Blues, gist_rainbow, rainbow, hsv, seismic,
            log=False):    
    width = len(df.columns)/7*10
    height = len(df.index)/7*10

    fig, ax = plt.subplots(figsize=(20,60))#(figsize=(width,height))

    #cmap, norm = mcolors.from_levels_and_colors([0, 0.05, 1],['Teal', 'MidnightBlue'] ) # ['MidnightBlue', Teal]['Darkgreen', 'Darkred']

    heatmap = ax.pcolor(df ,
                        edgecolors=edgecolors,  # put white lines between squares in heatmap
                        cmap=cmap,
                        norm=mpl.colors.LogNorm() if log else None)
    data = df.values
    for y in range(data.shape[0]):
        for x in range(data.shape[1]):
            plt.text(x + 0.5 , y + 0.5, '%.4f' % data[y, x], #data[y,x] +0.05 , data[y,x] + 0.05
                 horizontalalignment='center',
                 verticalalignment='center',
                 color='w',size=30)


    ax.autoscale(tight=True)  # get rid of whitespace in margins of heatmap
    ax.set_aspect('equal')  # ensure heatmap cells are square
    ax.xaxis.set_ticks_position('top')  # put column labels at the top
    ax.tick_params(bottom='off', top='off', left='off', right='off')  # turn off ticks

    ax.set_yticks(np.arange(len(df.index)) + 0.5)
    ax.set_yticklabels(df.index, size=30)
    ax.set_xticks(np.arange(len(df.columns)) + 0.5)
    ax.set_xticklabels(df.columns, size= 20)


    from mpl_toolkits.axes_grid1 import make_axes_locatable
    divider = make_axes_locatable(ax)
    cax = divider.append_axes("right", "3%", pad="1%")
    cbar = fig.colorbar(heatmap, cax=cax)
    cbar.ax.set_ylabel('Difference', fontsize=30) 

函数调用的输出:

heatmap_binary(dataframe)

有什么建议吗?

【问题讨论】:

    标签: python matplotlib colorbar


    【解决方案1】:

    使用tick_params():

    cax.tick_params(labelsize=20)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-19
      • 2013-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多