- 论坛徽章:
- 0
|
边学习边整理。方便以后的直接使用处理!
示例一
功能描述:绘制直线的方法
import matplotlib.pyplot as plt
plt.plot([1,2,3,4],[1,4,9,16],"ro",color="blue") 表示直接用点来划、颜色为blue
plt.ylabel("some")
plt.show()
示例二
功能:能够在一个图像里面描述两个子图像出来!
import numpy as np
import matplotlib.pyplot as plt
def f(t):
return np.exp(-t) * np.cos(2*np.pi*t)
t1 = np.arange(0.0, 5.0, 0.1)
t2 = np.arange(0.0, 5.0, 0.02)
plt.figure(1)
plt.subplot(211) 子图像
plt.plot(t1, f(t1), 'bo', t2, f(t2), 'k')
plt.subplot(212)
plt.plot(t2, np.cos(2*np.pi*t2), 'r--')
示例三、使用文字说明
import numpy as np
import matplotlib.pyplot as plt
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)
有一个问题:如何动态调整其显示的位置呢?
示例四、学习legend 的使用!
将每一条线段的颜色表示哪台主机标识出来!我要的效果就是这个了!
String
Number
upper right
1
upper left
2
lower left
3
lower right
4
right
5
center left
6
center right
7
lower center
8
upper center
9
center
10The location of the legend can be specified by the keyword argument
loc, either by string or a integer number.(这个表是loc的参数值!)
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/84280/showart_2104293.html |
|