小编tak*_*nbo的帖子

在matplotlib中更改colorbars的fontsize

我在以下代码中调整颜色条上的刻度字体大小时遇到​​困难.

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()
Run Code Online (Sandbox Code Playgroud)

谁能告诉我包含fontsize参数的正确语法?

matplotlib python-2.7 colorbar

3
推荐指数
3
解决办法
1万
查看次数

以与轴的纵横比一致的物理单位重新缩放箭矢箭头

在过去的几个小时中,我一直在尝试自定义matplotlib.quiver,但运气不佳。该文档非常混乱,我无法解析出如何设置每个参数。在我的轴上,一个垂直像素的物理距离比一个水平像素的物理距离小得多,我想颤抖一下,将箭头自动缩放为该纵横比。我现在得到的是带有以下代码的水平箭头:

Tlevs = np.arange(-1.,8.5,.5) + 0.
yy, zz = np.meshgrid(ds.YC, ds.Z)

fig, ax = plt.subplots(figsize=(8,5))
fig.set_tight_layout(True)
im = ax.contourf(T_clim.YC, T_clim.Z, T_clim, levels=Tlevs)
ax.quiver(yy[::3,::10], zz[::3,::10], 
          vpFep_b[::3,::10], wpFep_b[::3,::10], 
          pivot='mid', angles='xy', units='xy')
ax.set_xlabel('Y [m]', fontsize=13)
ax.set_ylabel('Depth [m]', fontsize=13)
cbar = fig.colorbar(im, ax=ax)
cbar.set_label(r"[$^\circ$C]")
Run Code Online (Sandbox Code Playgroud)

颤动叠加的轮廓图

将quiver选项设置为以下选项只会给出箭头应为的点:

ax.quiver(yy[::3,::10], zz[::3,::10], 
              vpFep_b[::3,::10], wpFep_b[::3,::10], 
              pivot='mid', angles='xy', scale_units='xy', scales=1.)
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

和:

ax.quiver(yy[::3,::10], zz[::3,::10], 
              vpFep_b[::3,::10], wpFep_b[::3,::10], 
              pivot='mid', angles='xy', scale_units='xy')
Run Code Online (Sandbox Code Playgroud)

给出以下错误:

/home/takaya/miniconda3/envs/uptodate/lib/python3.6/site-packages/matplotlib/quiver.py:666: RuntimeWarning: divide by zero encountered in double_scalars
  length = a * (widthu_per_lenu / (self.scale * self.width))
/home/takaya/miniconda3/envs/uptodate/lib/python3.6/site-packages/matplotlib/quiver.py:666: RuntimeWarning: invalid …
Run Code Online (Sandbox Code Playgroud)

python vector matplotlib

1
推荐指数
1
解决办法
1817
查看次数

标签 统计

matplotlib ×2

colorbar ×1

python ×1

python-2.7 ×1

vector ×1