If you have 2D data that you want to check immediately what the contents are, you can instantly create a diagram of that data by creating the following function in python in advance. For those who don't care about the detailed settings in the figure and just want to be easy.
quick.py
def draw(data,cb_min,cb_max): #cb_min,cb_max:Values at the bottom and top of the colorbar
import numpy as np
import matplotlib.pyplot as plt
X,Y=np.meshgrid(np.arange(data.shape[1]),np.arange(data.shape[0]))
plt.figure(figsize=(10,4)) #Specify the aspect ratio of the figure
div=20.0 #How many colors to use to draw the figure
delta=(cb_max-cb_min)/div
interval=np.arange(cb_min,abs(cb_max)*2+delta,delta)[0:int(div)+1]
plt.contourf(X,Y,data,interval)
plt.show()
with this,
In[10]: import quick
In[11]: quick.draw(data,-2,32)
If you execute, the contents of the 2D array created by numpy will be output as a color contour diagram.
In[12]: quick.draw(data[:,::-1],-2,32)
In[12]: quick.draw(data[::-1,:],-2,32)
In[12]: quick.draw(data[:,::-1].transpose(),-2,32)
Invert left and right and then transpose
In[12]: quick.draw(data[::-1,:][:,::-1],-2,32)
Flip upside down and then flip left and right
Reference URL: http://seesaawiki.jp/met-python/d/matplotlib
Recommended Posts