極座標表示の散布図
add_subplotの引数にprojection='polar'を指定することで極座標にできる。
import numpy as np
import matplotlib.pyplot as plt
N = 100
r = np.random.rand(N)
theta = 2 * np.pi * np.random.rand(N)
fig = plt.figure(figsize=(8,8))
ax = fig.add_subplot(111, projection='polar')
ax.scatter(theta, r)
ax.set_title('Polar coordinates',fontsize=18)
点の大きさ
import numpy as np
import matplotlib.pyplot as plt
N = 100
r = np.random.rand(N)
theta = 2 * np.pi * np.random.rand(N)
fig = plt.figure(figsize=(8,8))
ax = fig.add_subplot(111, projection='polar')
ax.scatter(theta, r, s=100)
ax.set_title('Polar coordinates',fontsize=18)
角度の範囲指定
import numpy as np
import matplotlib.pyplot as plt
N = 100
r = np.random.rand(N)
theta = 2 * np.pi * np.random.rand(N)
fig = plt.figure(figsize=(8,8))
ax = fig.add_subplot(111, projection='polar')
ax.scatter(theta, r)
ax.set_title('Polar coordinates',fontsize=18)
ax.set_thetamin(0)
ax.set_thetamax(180)
r方向の範囲指定
import numpy as np
import matplotlib.pyplot as plt
N = 100
r = np.random.rand(N)
theta = 2 * np.pi * np.random.rand(N)
fig = plt.figure(figsize=(8,8))
ax = fig.add_subplot(111, projection='polar')
ax.scatter(theta, r)
ax.set_title('Polar coordinates',fontsize=18)
ax.set_rmin(0)
ax.set_rmax(0.5)
参考URL https://matplotlib.org/3.3.1/gallery/pie_and_polar_charts/polar_scatter.html