Matplotlib: Charts

Polar chart

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

r = np.arange(0, 2, 0.01)
theta = 2 * np.pi * r

ax = plt.subplot(111, projection='polar')
ax.plot(theta, r)
ax.set_rmax(2)
ax.set_rticks([0.5, 1, 1.5, 2])  
ax.set_rlabel_position(-22.5)
ax.grid(True)
ax.set_title("A line plot on a polar axis", va='bottom')

plt.show()
  • Show
Matplotlib: Charts_第1张图片
polar chart
  • read more

polar_demo.py

polar_legend.py

Pie chart

  • Code
import matplotlib.pyplot as plt

labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
sizes = [15, 30, 45, 10]
explode = (0, 0.1, 0, 0)

fig1, ax1 = plt.subplots()
ax1.pie(sizes, explode=explode, labels=labels, autopct='%1.1f%%',
        shadow=True, startangle=90)
ax1.axis('equal') 

plt.show()
  • Show
Matplotlib: Charts_第2张图片
Pie chart
  • read more

pie_demo_features.py

Polar-bar chart

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


N = 20
theta = np.linspace(0.0, 2 * np.pi, N, endpoint=False)
radii = 10 * np.random.rand(N)
width = np.pi / 4 * np.random.rand(N)

ax = plt.subplot(111, projection='polar')
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()
  • Show
Matplotlib: Charts_第3张图片
Polar-bar chart
  • read more

polar_bar_demo.py

你可能感兴趣的:(Matplotlib: Charts)