全部博文(2065)
分类: Python/Ruby
2009-11-26 10:26:43
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 | 10 |
The location of the legend can be specified by the keyword argument
loc, either by string or a integer number.(这个表是loc的参数值!)