hdml指的是什么接口
295
2022-09-03
《Python数据可视化之matplotlib实践》 源码 第一篇 入门 第二章(Python数据可视化之matplotlib精进)
图 2.1
import matplotlib as mplimport matplotlib.pyplot as pltmpl.rcParams['font.sans-serif']=['SimHei']mpl.rcParams['axes.unicode_minus']=Falsex=[1,2,3,4,5,6,7,8]y=[3,1,4,5,8,9,7,2]plt.bar(x, y, align='center',color='c', tick_label=['q','a','c','e','r', 'j','b', 'p'], hatch='/')plt.xlabel('箱子编号')plt.ylabel('箱子重量(kg)')plt.show()
View Code
===================================================
图 2.2
import matplotlib as mplimport matplotlib.pyplot as pltmpl.rcParams['font.sans-serif']=['SimHei']mpl.rcParams['axes.unicode_minus']=Falsex=[1,2,3,4,5,6,7,8]y=[3,1,4,5,8,9,7,2]plt.barh(x, y, align='center',color='c', tick_label=['q','a','c','e','r', 'j','b', 'p'], hatch='/')plt.ylabel('箱子编号')plt.xlabel('箱子重量(kg)')plt.show()
View Code
===================================================
图 2.3
import matplotlib as mplimport matplotlib.pyplot as pltimport numpy as npmpl.rcParams['font.sans-serif']=['SimHei']mpl.rcParams['axes.unicode_minus']=False boxWeight=np.random.randint(0,10,100)x=boxWeightbins=range(0,11,1)plt.hist(x, bins=bins, color='g', histtype='bar', rwidth=1, alpha=0.6, edgecolor='black')plt.xlabel('箱子重量 (kg)')plt.ylabel('销售数量 (个)')plt.show()
View Code
===================================================
图 2.4
import matplotlib as mplimport matplotlib.pyplot as pltimport numpy as npmpl.rcParams['font.sans-serif']=['SimHei']mpl.rcParams['axes.unicode_minus']=False kinds=['简易箱','保温箱','行李箱','密封箱']colors=['#e41a1c', '#377eb8', '#4daf4a', '#984ea3']soldNums=[0.05, 0.45, 0.15, 0.35]plt.pie(soldNums, labels=kinds, autopct='%3.1f%%', startangle=60, colors=colors)plt.title('不同箱子类型的销售数量占比')plt.show()
View Code
===================================================
图 2.5
import matplotlib as mplimport matplotlib.pyplot as pltimport numpy as npbarSlices=18theta=np.linspace(0.0, 2*np.pi, barSlices, endpoint=False)r=30*np.random.rand(barSlices)plt.polar(theta, r, color='chartreuse', linewidth=2, marker='*', mfc='b', ms=10)plt.show()
View Code
===================================================
图 2.6
import matplotlib as mplimport matplotlib.pyplot as pltimport numpy as npa=np.random.randn(100)b=np.random.randn(100)plt.scatter(a, b, s=np.power(10*a+20*b,2), c=np.random.rand(100), cmap=mpl.cm.RdYlBu,marker='o')plt.show()
View Code
===================================================
图 2.7
import matplotlib as mplimport matplotlib.pyplot as pltimport numpy as npx=np.linspace(0.5, 2*np.pi, 20)y=np.random.randn(20)plt.stem(x,y,linefmt='-.', markerfmt='*', basefmt='-')plt.show()
View Code
===================================================
图 2.8
import matplotlib as mplimport matplotlib.pyplot as pltimport numpy as npmpl.rcParams['font.sans-serif']=['SimHei']mpl.rcParams['axes.unicode_minus']=False x=np.random.randn(1000)plt.boxplot(x)plt.xticks([1], ['随机数生成器AlphaRM'])plt.ylabel("随机数值")plt.title("随机数生成器抗干扰能力的稳定性")plt.grid(axis='y', ls=':', lw=1, color='gray', alpha=0.4)plt.show()
View Code
===================================================
图 2.9
import matplotlib as mplimport matplotlib.pyplot as pltimport numpy as npx=np.linspace(0.1, 0.6, 6)y=np.exp(x)plt.errorbar(x, y, fmt='bo:', yerr=0.2, xerr=0.02)plt.xlim(0, 0.7)plt.show()
View Code
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~