python matplotlib简单示例

来源:互联网 发布:视频教程网站源码 编辑:程序博客网 时间:2024/05/29 10:29

1.1)

import   matplotlib.pyplot as pltimport numpy as npimport syst = 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 pltt = 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 pltimport numpy as npimport  syst = 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 pltimport numpy as npimport  syst = 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 pltplt.figure(1) # the first figureplt.subplot(211) #  the first subplot in the first figureplt.plot([1, 2, 3])plt.subplot(212) # the second subplot in the first figureplt.plot([4, 5, 6])plt.figure(2)# a second figureplt.plot([4, 5, 6]) # creates a subplot(111) by defaultplt.figure(1)plt.subplot(211) # make subplot(211) in figure1 currentplt.title('Easy as 1, 2, 3') # subplot 211 titleplt.show()

图 1.5:注意这里有两个图版:而不是一张图版里两张。
这里写图片描述
+++++++++++++++++++++++++++++++++++++++++++++++
1.6)

import numpy as npimport matplotlib.pyplot as plt# Fixing random state for reproducibility np.random.seed(19680801)mu, sigma = 100, 15x = mu + sigma * np.random.randn(10000)# the histogram of the datan, 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:
这里写图片描述

原创粉丝点击