今天把基本的畫圖技巧都學了一遍,以下是自己綜合後基本會用到的畫圖技巧:
import numpy as npfrom pylab import *import matplotlib.pyplot as pltimport random# Draw plot one:number = 256x = np.linspace(-np.pi,np.pi,number)y = np.sin(x)plt.subplot(2,1,1) # (行,列,活跃区)cr = np.random.random()cg = np.random.random()cb = np.random.random()plt.plot(x,y,color = (cr, cg, cb ),linewidth = 2.0, label ='sin(x)')legend(loc ='upper left')plt.xlabel('x',fontsize = 10)plt.ylabel(r'$\Delta$',fontsize =10)xlim(x.min()*1.1,x.max()*1.1)ylim(y.min()*1.1,y.max()*1.1)number2 = 100xx = np.random.rand(number2)yy = np.random.rand(number2)color = np.random.rand(number2)size = 20marker = 'o'colormap = plt.cm.get_cmap('BuPu_r') # _r let color of colorbar up-side-downplt.subplot(2,1,2)plt.subplots_adjust(hspace = 0.4)plt.scatter(xx,yy,size,color,marker,colormap)plt.xlabel(r'XX',fontsize = 10)plt.ylabel(r'YY',fontsize = 10)plt.colorbar()plt.show()# View all cmaps in python:plt.colormaps()import numpy as npimport matplotlib.pyplot as pltn = 100000x = np.random.standard_normal(n) # Normal distribution in xy = 2.0 + 3.0 * x + 4.0 * np.random.standard_normal(n) # Normal distribution in yplt.hexbin(x,y)plt.colorbar()plt.show()其中畫圖的顏色,在plt.plot()裡面用的繪圖顏色原則:
在colormap裡的顏色使用原則:

| 這封郵件來自 Evernote。Evernote 是您專屬的工作空間,免費下載 Evernote |

0 意見:
張貼留言