contourf

plt.ion()

img=plt.contourf(lons,lats,z1)

img2=plt.contourf(lons,lats,z2,levels=[-100,-50,50,100],colors=[[1,0,0,0.3],[1,1,1,0],[0,0,1,0.3]])

xsz=len(lons)

ysz=len(lats)

z1=np.sin(lats/180*2*np.pi).reshape(ysz,1) @ np.cos(lons/180*2*np.pi).reshape(1,xsz)

z2=lats.reshape(ysz,1)@lons.reshape(1,xsz)

z2=z2/z2.max()*100

lons=np.arange(0,360,2.5)

lats=np.arange(-88.75,90,2.5)

複数のパネルで同一のカラーバーを使うには,contourfなどにlevelsをオプション引数で指定する.その際に,levelの下限以下の値,上限以上の値が描画されるデータにある場合にはデフォルトだと塗り残しが出てしまうので,extend='both'をオプション引数で指定する.extend='max'で上限だけ,extend='min'で下限だけに,extendを適用する.

#デモスクリプトその1

import numpy as np

import matplotlib.pyplot as plt

xydata=np.random.randn(20,10)

clevs=np.arange(-1.2,1.3,0.2)

plt.subplot(121)

img=plt.contourf(xydata,levels=clevs)

plt.colorbar(img)

plt.subplot(122)

img=plt.contourf(xydata,levels=clevs,extend='both')

plt.colorbar(img)

plt.savefig('d:\\temp\demo_contourf_extend.png',size='a4')

plt.show()

二つのcontoufを透過を使って重ねることができる.

#透過をつかった図の重ね合わせのスクリプト例

from matplotlib import pyplot as plt

import numpy as np

To use the same color bar on multiple panels, specify "levels" as an optional arguments of contourf etc. However, if a value larger (smaller) than the upper (lower) limit of the levels is present in the data to be drawn, you will get a figure that has a white area corresponding to those large (small) data. You can avoid this problem by specifing optional argument "extend = 'both'".

# demo script

import numpy as np

import matplotlib.pyplot as plt

xydata=np.random.randn(20,10)

clevs=np.arange(-1.2,1.3,0.2)

plt.subplot(121)

img=plt.contourf(xydata,levels=clevs)

plt.colorbar(img)

plt.subplot(122)

img=plt.contourf(xydata,levels=clevs,extend='both')

plt.colorbar(img)

plt.savefig('d:\\temp\demo_contourf_extend.png',size='a4')

plt.show()

# It is possible to overlap two shading plots using transparency. The following is a sample script.

from matplotlib import pyplot as plt

import numpy as np

lons=np.arange(0,360,2.5)

lats=np.arange(-88.75,90,2.5)

xsz=len(lons)

ysz=len(lats)

z1=np.sin(lats/180*2*np.pi).reshape(ysz,1) @ np.cos(lons/180*2*np.pi).reshape(1,xsz)

z2=lats.reshape(ysz,1)@lons.reshape(1,xsz)

z2=z2/z2.max()*100

plt.ion()

img=plt.contourf(lons,lats,z1)

img2=plt.contourf(lons,lats,z2,levels=[-100,-50,50,100],colors=[[1,0,0,0.3],[1,1,1,0],[0,0,1,0.3]])