add_axes
plt.show()
cax_cbar=fig.add_axes(cbar_pos)
hcbar=plt.colorbar(img,cax=cax_cbar,orientation='horizontal')
hcbar.ax.tick_params(labelsize=10)
npnl=(n-1)*2+1
fig.add_axes(pnl_pos[npnl])
plt.plot(tsrs[n,:])
plt.title(pnlstr[npnl])
clevs=np.arange(-2.0,2.1,0.1)
clevs
fig=plt.figure()
for n in range(2):
npnl=(n-1)*2+0
fig.add_axes(pnl_pos[npnl])
img=plt.contourf(xydata[n,:,:],levels=clevs,extend='both')
plt.title(pnlstr[npnl])
pnlstr=['a) ','b) ','c) ','d) ']
xydata=np.random.randn(2,20,10)
tsrs=np.random.randn(2,30)
pnl_pos=[[0.05, 0.55, 0.4, 0.40], \
[0.05, 0.05, 0.4, 0.30], \
[0.55, 0.55, 0.4, 0.40], \
[0.55, 0.05, 0.4, 0.30]]
cbar_pos=[0.10, 0.48, 0.8, 0.03]
スクリプト例 (Example of script) ---------
import numpy as np
import matplotlib.pyplot as plt
使い方は
fig=plt.figure()
fig.add_axes([left, bottom, width, height])
ただし,カラーバーはcbarへのオプション引数caxにaxesインスタンスを渡す.
図(Figure)中の任意の場所にパネルやカラーバーを描くための,場所を設定する.
subplotはぱっと見には便利だが,細かい調整ができないので論文や学会発表用の図を作るには向かない.
Set location of a panel or colorbar in a figure.
"subplot" is useful for quick-looks, but not good enough for making figures for theses or papers or for meeting presentation.
Usage is
fig=plt.figure()
fig.add_axes([left, bottom, width, height])
For a colorbar, axes instance is set for optional argument "cax".
Example of script ---------
import numpy as np
import matplotlib.pyplot as plt
pnl_pos=[[0.05, 0.55, 0.4, 0.40], \
[0.05, 0.05, 0.4, 0.30], \
[0.55, 0.55, 0.4, 0.40], \
[0.55, 0.05, 0.4, 0.30]]
cbar_pos=[0.10, 0.48, 0.8, 0.03]
xydata=np.random.randn(2,20,10)
tsrs=np.random.randn(2,30)
pnlstr=['a) ','b) ','c) ','d) ']
clevs=np.arange(-2.0,2.1,0.1)
clevs
fig=plt.figure()
for n in range(2):
npnl=(n-1)*2+0
fig.add_axes(pnl_pos[npnl])
img=plt.contourf(xydata[n,:,:],levels=clevs,extend='both')
plt.title(pnlstr[npnl])
npnl=(n-1)*2+1
fig.add_axes(pnl_pos[npnl])
plt.plot(tsrs[n,:])
plt.title(pnlstr[npnl])
cax_cbar=fig.add_axes(cbar_pos)
hcbar=plt.colorbar(img,cax=cax_cbar,orientation='horizontal')
hcbar.ax.tick_params(labelsize=10)
plt.show()