极坐标轴上的散点图#

在此示例中,大小沿径向增加,颜色随角度增加(只是为了验证符号是否被正确分散).

import matplotlib.pyplot as plt
import numpy as np

# Fixing random state for reproducibility
np.random.seed(19680801)

# Compute areas and colors
N = 150
r = 2 * np.random.rand(N)
theta = 2 * np.pi * np.random.rand(N)
area = 200 * r**2
colors = theta

fig = plt.figure()
ax = fig.add_subplot(projection='polar')
c = ax.scatter(theta, r, c=colors, s=area, cmap='hsv', alpha=0.75)
polar scatter

具有偏移原点的极坐标轴上的散点图#

与前一个图的主要区别在于原点半径的配置,从而产生一个环.此外,theta 零位置设置为旋转绘图.

fig = plt.figure()
ax = fig.add_subplot(projection='polar')
c = ax.scatter(theta, r, c=colors, s=area, cmap='hsv', alpha=0.75)

ax.set_rorigin(-2.5)
ax.set_theta_zero_location('W', offset=10)
polar scatter

限制在扇区的极坐标轴上的散点图#

与之前的图的主要区别在于 theta 起始和结束限制的配置,从而产生一个扇区而不是一个完整的圆.

fig = plt.figure()
ax = fig.add_subplot(projection='polar')
c = ax.scatter(theta, r, c=colors, s=area, cmap='hsv', alpha=0.75)

ax.set_thetamin(45)
ax.set_thetamax(135)

plt.show()
polar scatter

参考

以下函数,方法,类和模块的用法在本例中显示:

  • matplotlib.axes.Axes.scatter / matplotlib.pyplot.scatter

  • matplotlib.projections.polar

  • matplotlib.projections.polar.PolarAxes.set_rorigin

  • matplotlib.projections.polar.PolarAxes.set_theta_zero_location

  • matplotlib.projections.polar.PolarAxes.set_thetamin

  • matplotlib.projections.polar.PolarAxes.set_thetamax

Tags: plot-style: polar plot-style: scatter level: beginner

脚本的总运行时间:(0 分钟 1.167 秒)

Gallery generated by Sphinx-Gallery