我正在尝试增加颜色栏中的值大小。似乎微不足道,但我无法弄清楚。
我制作了一张热图,这里是代码:
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)
Aany提示?
答案 0 :(得分:2)
使用tick_params()
:
cax.tick_params(labelsize=20)