您的位置:首页 > 编程语言 > Python开发

python matplotlib简单示例

2017-09-01 22:48 776 查看
1.1)

import   matplotlib.pyplot as plt
import numpy as np
import sys
t = np.arange(0.,5,0.2)

lines = plt.plot(t,t**2,'-')
plt.setp(lines,color='r')
#print plt.setp(lines)
plt.show(lines)


图 1.1:



++++++++++++++++++++++++++++++++++++++++

1.2)

import numpy as np
import matplotlib.pyplot as plt
t = np.arange(0., 5., 0.2)
plt.plot(t, t, 'r--', t, t**2, 'bs', t, t**3, 'g^')
plt.show()


图1.2



+++++++++++++++++++++++++++++++++++++

1.3)

import   matplotlib.pyplot as plt
import numpy as np
import  sys
t = np.arange(0.,5,0.2)
def f(t):
return np.exp(-t)
print f(t)

lines1 = plt.plot(t,f(t),'-')
lines2 = plt.plot(t,f(2*t),'-')
plt.figure(1)

plt.setp(lines1,color='r')

plt.setp(lines2,color='b')
plt.show([lines1,lines2])
#line.show()


图1.3:



++++++++++++++++++++++++++++++++++++++++

1.4)

import   matplotlib.pyplot as plt
import numpy as np
import  sys
t = np.arange(0.,5,0.2)
def f(t):
return np.exp(-t)

plt.figure(1)
plt.subplot(211)
plt.plot(t,f(t),'-')

plt.subplot(212)
plt.plot(t,f(t),'-')

plt.show()
#line.show()


图 1.4



+++++++++++++++++++++++++++++++++++++++

1.5)

import matplotlib.pyplot as plt
plt.figure(1) # the first figure
plt.subplot(211) #  the first subplot in the first figure
plt.plot([1, 2, 3])
plt.subplot(212) # the second subplot in the first figure
plt.plot([4, 5, 6])
plt.figure(2)# a second figure
plt.plot([4, 5, 6]) # creates a subplot(111) by default
plt.figure(1)
plt.subplot(211) # make subplot(211) in figure1 current
plt.title('Easy as 1, 2, 3') # subplot 211 title
plt.show()


图 1.5:注意这里有两个图版:而不是一张图版里两张。



+++++++++++++++++++++++++++++++++++++++++++++++

1.6)

import numpy as np
import matplotlib.pyplot as plt
# Fixing random state for reproducibility np.random.seed(19680801)
mu, sigma = 100, 15
x = mu + sigma * np.random.randn(10000)
# the histogram of the data

n, bins, patches = plt.hist(x, 50, normed=1, facecolor='g', alpha=0.75)
plt.xlabel('Smarts')
plt.ylabel('Probability')
plt.title('Histogram of IQ')
plt.text(60, .025, r'$\mu=100,\ \sigma=15$')
plt.axis([40, 160, 0, 0.03])
plt.grid(True)
plt.show()


图1.6:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python