matplotlib 绘图实例
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
np.random.seed(0)
mu, sigma = 100, 20 # 均值和标准差
a = np.random.normal(mu, sigma, size = 100)
##plt.hist(a,20,histtype="stepfilled",facecolor="b",alpha=0.75)
plt.hist(a, 40, histtype = 'stepfilled', facecolor = 'b', alpha = 0.75)
plt.title('Histogram')
plt.show()
print(np.pi)
matplotlib 绘图极坐标图实例
N = 20
theta = np.linspace(0.0, 2*np.pi, N, endpoint = False)
radii = 10 * np.random.rand(N)
print(radii)
width = np.pi / 4 * np.random.rand(N)
print(width)
ax = plt.subplot(1,1,1, projection = 'polar')
print(ax)
bars = ax.bar(theta, radii, width = width, bottom = 0.0)
for r, bar in zip(radii, bars):
bar.set_facecolor(plt.cm.viridis(r/10))
bar.set_alpha(0.5)
plt.show()
matplotlib 绘图散点图实例(运用面向对象的方法)
help(plt.plot)
fig, ax = plt.subplots()
print(10*np.random.randn(100))
ax.plot(10*np.random.randn(100), 10*np.random.randn(100),'o')
ax.set_title('Simple Scatter')
plt.show()