在matplotlib中更改colorbars的fontsize

时间:2016-10-21 20:07:54

标签: python-2.7 matplotlib colorbar

我无法在以下代码中调整彩条上刻度线的字体大小。

fig = plt.figure(figsize=(10,6))

ax = fig.add_subplot(111)
im = ax.pcolor(np.ma.masked_invalid(np.roll(lon, -1100, axis=1)[:2100, :3500]), 
           np.ma.masked_invalid(np.roll(lat, -1100, axis=1)[:2100, :3500]), 
           np.ma.masked_invalid(np.roll(np.absolute(zeta_Mar), -1100, axis=1)[:2100, :3500]),
              cmap='Reds', norm=colors.LogNorm(vmin=1e-6, vmax=1e-4))
ax.set_xlabel('Longitude', fontsize=14)
ax.set_xlabel('Latitude', fontsize=14)
cbar_axim = fig.add_axes([0.95, 0.15, 0.03, 0.7])
cbar = fig.colorbar(im, cax=cbar_axim, ticks=[1e-6, 1e-5, 1e-4])
cbar.set_ticklabels([r'$-10^{-6}$', r'$10^{-5}$', r'$10^{-4}$'])
cbar.set_label(r'$\zeta\ [s^{-1}]$', fontsize=16)

plt.show()

有人能告诉我包含fontsize参数的正确语法吗?

3 个答案:

答案 0 :(得分:9)

使用Dim Secondcol_lrow As Long ' Performed on Master sheet Secondcol_lrow As Long Windows("Master.xlsm").Activate Secondcol_lrow = Cells(Rows.Count, 2).End(xlUp).Row + 1 For i = 2 To DateTime_Column + 1 Cells(Secondcol_lrow, i) = Features(1, i - 1) Cells(Secondcol_lrow, i).Interior.ColorIndex = 15 Next i Secondcol_lrow = Cells(Rows.Count, 2).End(xlUp).Row + 1 If sum >= 3 Then Range("A" & Secondcol_lrow).Interior.ColorIndex = 3 lColplusone = 1 ' last column with data in it ArraySize = DateTime_Column + 1 ColLtr1 = Replace(Cells(1, lColplusone).Address(True, False), "$1", "") Range(ColLtr1 & Secondcol_lrow).Resize(1, ArraySize) = Cpk ' Prints contents of Cpk at last column in first row End If

来自herehere

答案 1 :(得分:1)

如果我使用@Yugi的答案,我会得到乳胶错误。您还可以使用以下方法设置fontsize:

<ul>
   <li>Get to know the business</li>
   <li>Get to know people (stakeholders, key players, cross-functional partners, etc.)</li>
   <li>Learn how the team's priorities impact our mission</li>
   <li>Get to know your projects, the team's projects, who's involved, and your onboarding goals</li>
</ul>

答案 2 :(得分:1)

如果您尝试增加字体大小,但是由于字体大而一些数字消失了,您可以这样做

cbar = plt.colorbar()
for t in cbar.ax.get_yticklabels():
     t.set_fontsize(20)