Python matplotlib绘制极坐标图-演道网
1、极坐标散点图
N = 150
r = 2 * np.random.rand(N)
theta = 2 * np.pi * np.random.rand(N)
area = 200 * r**2
colors = theta
ax = plt.subplot(111, projection=’polar’)
c = ax.scatter(theta, r, c=colors, s=area, cmap=’hsv’, alpha=0.65)
plt.show()
绘制结果如下:
2、极坐标饼状图
import numpy as np
import matplotlib.pyplot as plt
# 计算饼图
N = 20
theta = np.linspace(0.0, 3 * 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.6)
plt.show()
绘制结果如下:
更多Python相关信息见Python 专题页面 https://www.linuxidc.com/topicnews.aspx?tid=17
Linux公社的RSS地址:https://www.linuxidc.com/rssFeed.as
转载自演道,想查看更及时的互联网产品技术热点文章请点击http://go2live.cn