O.r*_*rka 4 python matplotlib figure polar-coordinates
我试图弄清楚如何在极坐标图中的两点之间创建圆弧,但我绘制的线是连接它们的直线,即使该图是极坐标的。
我需要使用不同的绘图函数来代替吗ax.plot?
我注意到有些补丁matplotlib可能是我应该使用的,但我不确定如何以这种方式添加它们。
如何在极坐标图上从 A 点和 B 点绘制一条曲线?
# Create polar plot object
with plt.style.context("seaborn-white"):
fig = plt.figure(figsize=(5,5))
ax = fig.add_subplot(111, projection="polar")
# Draw 3 lines
for degree in [90, 210, 330]:
rad = np.deg2rad(degree)
ax.plot([rad,rad], [0,1], color="black", linewidth=2)
# Connect two points with a curve
for curve in [[[90, 210], [0.5, 0.8]]]:
curve[0] = np.deg2rad(curve[0])
ax.plot(curve[0], curve[1])
Run Code Online (Sandbox Code Playgroud)
极坐标投影意味着您不再使用 x,y 坐标系,而是使用极坐标系。尽管如此,两点之间的图仍然是它们之间的一条直线。
你想要做的是自己定义弧,如下所示:
from matplotlib import pyplot as plt
from scipy.interpolate import interp1d
import numpy as np
with plt.style.context("seaborn-white"):
fig = plt.figure(figsize=(5,5))
ax = fig.add_subplot(111, projection="polar")
# Draw 3 lines
for degree in [90, 210, 330]:
rad = np.deg2rad(degree)
ax.plot([rad,rad], [0,1], color="black", linewidth=2)
# Connect two points with a curve
for curve in [[[90, 210], [0.5, 0.8]]]:
curve[0] = np.deg2rad(curve[0])
x = np.linspace( curve[0][0], curve[0][1], 500)
y = interp1d( curve[0], curve[1])( x)
ax.plot(x, y)
plt.show()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4205 次 |
| 最近记录: |