10 Python Matplotlib draw polar plots and scatter plots

matplotlib drawing example

import numpy as np
import matplotlib.pyplot as plt
import matplotlib



np.random.seed(0)
mu, sigma = 100, 20 # 均值和标准差
a = np.random.normal(mu, sigma, size = 100)
##plt.hist(a,20,histtype="stepfilled",facecolor="b",alpha=0.75)
plt.hist(a, 40, histtype = 'stepfilled', facecolor = 'b', alpha = 0.75)
plt.title('Histogram')
plt.show()

print(np.pi)

Examples of matplotlib plotting polar plots

N = 20
theta = np.linspace(0.0, 2*np.pi, N, endpoint = False)
radii = 10 * np.random.rand(N)
print(radii)
width = np.pi / 4 * np.random.rand(N)
print(width)
ax = plt.subplot(1,1,1, projection = 'polar')
print(ax)
bars = ax.bar(theta, radii, width = width, bottom = 0.0)
for r, bar in zip(radii, bars):
  bar.set_facecolor(plt.cm.viridis(r/10))
  bar.set_alpha(0.5)
plt.show()

matplotlib example of plotting scatterplot (using object-oriented approach)

help(plt.plot)
fig, ax = plt.subplots()
print(10*np.random.randn(100))
ax.plot(10*np.random.randn(100), 10*np.random.randn(100),'o')
ax.set_title('Simple Scatter')

plt.show()
Published 36 original articles · praised 0 · visits 612

Guess you like

Origin blog.csdn.net/Corollary/article/details/105545939