《Python数据可视化之matplotlib实践》 源码 第四篇 扩展 第十二章(利用matplotlib做数据可视化)

网友投稿 340 2022-09-03


《Python数据可视化之matplotlib实践》 源码 第四篇 扩展 第十二章(利用matplotlib做数据可视化)

图  12.1

import matplotlib.pyplot as pltimport numpy as npbarSlices=12theta=np.linspace(0.0, 2*np.pi, barSlices, endpoint=False)radii=30*np.random.rand(barSlices)width=2*np.pi/barSlicescolors=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()

View Code

---------------------------------------------------------

图  12.3

import matplotlib.pyplot as pltimport numpy as nphexHtml=["#d73027", "#f46d43", "#fdae61", "#fee090", "#ffffbf", "#e0f3f8", "#abd9e9", "#74add2", "#4575b4"]sample=10000fig, 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()

View Code

---------------------------------------------------------

图  12.4

import matplotlib.pyplot as pltimport numpy as nprd=np.random.rand(10, 10)plt.pcolor(rd, cmap="BuPu")plt.colorbar()plt.show()

View Code

---------------------------------------------------------

图  12.5

import matplotlib.pyplot as pltimport matplotlib as mplimport numpy as npa = np.random.rand(100)b = np.random.rand(100)exponent = 2plt.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()

View Code

---------------------------------------------------------

图  12.6

import matplotlib.pyplot as pltimport matplotlib as mplimport numpy as npbarSlices=12theta=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()

View Code

---------------------------------------------------------

图  12.7

import matplotlib.pyplot as pltimport matplotlib as mplimport numpy as nps=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()

View Code

---------------------------------------------------------

图  12.8

import matplotlib.pyplot as pltimport matplotlib as mplimport scipy.miscascent=scipy.misc.ascent()plt.imshow(ascent, cmap=mpl.cm.gray)plt.colorbar()plt.show()

View Code

---------------------------------------------------------


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:《Python数据可视化之matplotlib实践》 源码 第一篇 入门 第一章(利用matplotlib做数据可视化)
下一篇:使用MDC实现日志链路跟踪
相关文章

 发表评论

暂时没有评论,来抢沙发吧~