2017年2月6日 星期一

python 畫圖

今天把基本的畫圖技巧都學了一遍,以下是自己綜合後基本會用到的畫圖技巧:

import numpy as np
from pylab import *
import matplotlib.pyplot as plt
import random
 
# Draw plot one:
number  = 256
x = 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 = 100
xx = np.random.rand(number2)
yy = np.random.rand(number2)
color = np.random.rand(number2)
size = 20
marker = 'o'
colormap = plt.cm.get_cmap('BuPu_r')  
# _r let color of colorbar up-side-down
plt.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 np
import matplotlib.pyplot as plt
 
n = 100000
x = np.random.standard_normal(n)
# Normal distribution in x
y = 2.0 + 3.0 * x + 4.0 * np.random.standard_normal(n) 
# Normal distribution in y
plt.hexbin(x,y)
plt.colorbar()
plt.show()

其中畫圖的顏色,在plt.plot()裡面用的繪圖顏色原則: 


在colormap裡的顏色使用原則:

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

0 意見:

張貼留言

Contact

Get in touch with me


Adress/Street

12 Street West Victoria 1234 Australia

Phone number

+(12) 3456 789

Website

www.johnsmith.com