Matplotlib中的半极图或四分之一极图?

2024-05-16 01:07:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试绘制一个180度的极坐标图,而不是Matplotlib中的360度,类似于MATLAB中的http://www.mathworks.com/matlabcentral/fileexchange/27230-half-polar-coordinates-figure-plot-function-halfpolar。有什么想法吗?


Tags: comhttpplotmatplotlibwww绘制figurematlab
2条回答

在matplotlib 2.1或更高版本中,可以执行以下操作。matplotlib页上还有an example
可以使用通常的极坐标图ax = fig.add_subplot(111, polar=True),并限制θ范围。对于半极坐标图

ax.set_thetamin(0)
ax.set_thetamax(180)

或对于四分之一极坐标图

ax.set_thetamin(0)
ax.set_thetamax(90)

完整示例:

import matplotlib.pyplot as plt
import numpy as np

theta = np.linspace(0,np.pi)
r = np.sin(theta)

fig = plt.figure()
ax = fig.add_subplot(111, polar=True)
c = ax.scatter(theta, r, c=r, s=10, cmap='hsv', alpha=0.75)

ax.set_thetamin(0)
ax.set_thetamax(180)

plt.show()

enter image description here

官方matplotlib文档中的示例代码可能会稍微模糊一些,如果有人只需要简单的四分之一的半图。 我写了一段代码片段,可以帮助不太熟悉AxisArtistshere的人。

The output image of this code snippet

相关问题 更多 >