如何在 matplotlib plt.polar 图中设置轴限制
How to set the axis limit in a matplotlib plt.polar plot
假设我有以下极坐标图:
a=-0.49+1j*1.14
plt.polar([0,angle(x)],[0,abs(x)],linewidth=5)
我想将径向限制调整为 0 到 2。
最好的方法是什么?
请注意,我特别询问 plt.polar()
方法(而不是在类似问题中常见的普通图中使用 polar=True
参数)。
这似乎可行,除非我从控制台(Spyder、Win7)进行绘图:
>>> ax=plt.gca()
>>> ax.set_rlim(0,2)
你可以直接使用经典方法
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(-180.0,190.0,10)
theta = (np.pi/180.0 )*x # in radians
offset = 2.0
R1 = [-0.358,-0.483,-0.479,-0.346,-0.121,0.137,0.358,0.483,0.479,0.346,0.121,\
-0.137,-0.358,-0.483,-0.479,-0.346,-0.121,0.137,0.358,0.483,0.479,0.346,0.121,\
-0.137,-0.358,-0.483,-0.479,-0.346,-0.121,0.137,0.358,0.483,0.479,0.346,0.121,\
-0.137,-0.358]
fig1 = plt.figure()
ax1 = fig1.add_axes([0.1,0.1,0.8,0.8],polar=True)
ax1.set_ylim(-2,2)
ax1.set_yticks(np.arange(-2,2,0.5))
ax1.plot(theta,R1,lw=2.5)
plt.show()
解决 OP 的更简单方法可能是:
ax.set_ylim([0,2])
假设我有以下极坐标图:
a=-0.49+1j*1.14
plt.polar([0,angle(x)],[0,abs(x)],linewidth=5)
我想将径向限制调整为 0 到 2。
最好的方法是什么?
请注意,我特别询问 plt.polar()
方法(而不是在类似问题中常见的普通图中使用 polar=True
参数)。
这似乎可行,除非我从控制台(Spyder、Win7)进行绘图:
>>> ax=plt.gca()
>>> ax.set_rlim(0,2)
你可以直接使用经典方法
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(-180.0,190.0,10)
theta = (np.pi/180.0 )*x # in radians
offset = 2.0
R1 = [-0.358,-0.483,-0.479,-0.346,-0.121,0.137,0.358,0.483,0.479,0.346,0.121,\
-0.137,-0.358,-0.483,-0.479,-0.346,-0.121,0.137,0.358,0.483,0.479,0.346,0.121,\
-0.137,-0.358,-0.483,-0.479,-0.346,-0.121,0.137,0.358,0.483,0.479,0.346,0.121,\
-0.137,-0.358]
fig1 = plt.figure()
ax1 = fig1.add_axes([0.1,0.1,0.8,0.8],polar=True)
ax1.set_ylim(-2,2)
ax1.set_yticks(np.arange(-2,2,0.5))
ax1.plot(theta,R1,lw=2.5)
plt.show()
解决 OP 的更简单方法可能是:
ax.set_ylim([0,2])