图 12.1
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
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
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
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
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
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
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()
---------------------------------------------------------