首页 > 代码库 > matplotlib例子
matplotlib例子
pyplot饼图的绘制
1 import matplotlib.pyplot as plt 2 3 labels = ‘Frogs‘, ‘Hogs‘, ‘Dogs‘, ‘Logs‘ 4 sizes = [15, 30, 45, 10] 5 explode = (0, 0.1, 0, 0) 6 7 plt.pie(sizes, explode=explode, labels=labels, autopct=‘%1.1f%%‘, shadow=False, startangle=90) 8 9 plt.axis(‘equal‘) 10 plt.show()
pyplot直方图的绘制
1 import numpy as np 2 import matplotlib.pyplot as plt 3 4 np.random.seed(0) 5 mu, sigma = 100, 20 6 a = np.random.normal(mu, sigma,size=100) 7 8 plt.hist(a, 40, normed=1, histtype=‘stepfilled‘, facecolor=‘b‘, alpha=0.75) 9 plt.title(‘Histogram‘) 10 11 plt.show()
pyplot极坐标图的绘制
1 import numpy as np 2 import matplotlib.pyplot as plt 3 4 N = 20 5 theta = np.linspace(0.0, 2*np.pi, N, endpoint=False) 6 radii = 10*np.random.rand(N) 7 width = np.pi / 4 * np.random.rand(N) 8 9 ax = plt.subplot(111,projection=‘polar‘) 10 bars = ax.bar(theta, radii, width=width, bottom=0.0) 11 12 for r, bar in zip(radii, bars): 13 bar.set_facecolor(plt.cm.viridis(r / 10.)) 14 bar.set_alpha(0.5) 15 16 plt.show()
pyplot散点图的绘制
1 import numpy as np 2 import matplotlib.pyplot as plt 3 4 fig, ax = plt.subplots() 5 ax.plot(10*np.random.random(100),10*np.random.rand(100),‘o‘) 6 ax.set_title(‘Simple Scatter‘) 7 8 plt.show()
matplotlib例子
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。