《Python数据可视化之matplotlib实践》 源码 第四篇 扩展 第十二章
图 12.1
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
import matplotlib.pyplot as plt import numpy as np barSlices=12 theta=np.linspace(0.0, 2*np.pi, barSlices, endpoint=False) radii=30*np.random.rand(barSlices) width=2*np.pi/barSlices colors=np.array(["c", "m", "y", "b", "#C67171", "#C1CDCD", "#FFEC8B", "#A0522D", "red", "burlywood", "chartreuse", "green"]) fig=plt.figure() ax=fig.add_subplot(111, polar=True) bars=ax.bar(theta, radii, width=width, color=colors, bottom=0.0) plt.show()
---------------------------------------------------------
图 12.3
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
import matplotlib.pyplot as plt import numpy as np hexHtml=["#d73027", "#f46d43", "#fdae61", "#fee090", "#ffffbf", "#e0f3f8", "#abd9e9", "#74add2", "#4575b4"] sample=10000 fig, ax = plt.subplots(1, 1) for j in range(len(hexHtml)): y=np.random.normal(0, 0.1, size=sample).cumsum() x=np.arange(sample) ax.scatter(x, y, label=str(j), linewidths=0.2, edgecolors="grey", facecolor=hexHtml[j]) ax.legend() plt.show()
---------------------------------------------------------
图 12.4
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
import matplotlib.pyplot as plt import numpy as np rd=np.random.rand(10, 10) plt.pcolor(rd, cmap="BuPu") plt.colorbar() plt.show()
---------------------------------------------------------
图 12.5
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
import matplotlib.pyplot as plt import matplotlib as mpl import numpy as np a = np.random.rand(100) b = np.random.rand(100) exponent = 2 plt.subplot(131) plt.scatter(a, b, np.sqrt(np.power(a, exponent)+np.power(b, exponent))*100, c=np.random.rand(100), cmap=mpl.cm.jet, marker="o", zorder=1) plt.subplot(132) plt.scatter(a, b, 50, marker="o", zorder=10) plt.subplot(133) plt.scatter(a, b, 50, c=np.random.rand(100), cmap=mpl.cm.BuPu, marker="+", zorder=100) plt.show()
---------------------------------------------------------
图 12.6
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
import matplotlib.pyplot as plt import matplotlib as mpl import numpy as np barSlices=12 theta=np.linspace(0.0, 2*np.pi, barSlices, endpoint=False) radii=30*np.random.rand(barSlices) width=np.pi/4*np.random.rand(barSlices) fig=plt.figure() ax=fig.add_subplot(111, polar=True) bars=ax.bar(theta, radii, width=width, bottom=0.0) for r, bar in zip(radii, bars): bar.set_facecolor(mpl.cm.Accent(r/30.0)) bar.set_alpha(r/30.0) plt.show()
---------------------------------------------------------
图 12.7
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
import matplotlib.pyplot as plt import matplotlib as mpl import numpy as np s=np.linspace(-0.5, 0.5, 1000) x, y=np.meshgrid(s, s) z=x**2+y**2+np.power(x**2+y**2, 2) fig, ax=plt.subplots(1, 1) cs=plt.contour(x, y, z, cmap=mpl.cm.hot) plt.clabel(cs, fmt="%3.2f") plt.colorbar(cs) plt.show()
---------------------------------------------------------
图 12.8
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
import matplotlib.pyplot as plt import matplotlib as mpl import scipy.misc ascent=scipy.misc.ascent() plt.imshow(ascent, cmap=mpl.cm.gray) plt.colorbar() plt.show()
---------------------------------------------------------
本博客是博主个人学习时的一些记录,不保证是为原创,个别文章加入了转载的源地址,还有个别文章是汇总网上多份资料所成,在这之中也必有疏漏未加标注处,如有侵权请与博主联系。
如果未特殊标注则为原创,遵循 CC 4.0 BY-SA 版权协议。
posted on 2020-07-07 13:26 Angry_Panda 阅读(430) 评论(0) 编辑 收藏 举报