将Matplotlib补丁与极坐标图混合使用?

4
我正在尝试在极坐标系中绘制一些数据,但是我不想使用Matplotlib的函数自带的标签、轴等。我只需要裸的图形,因为我正在使用手动绘制的补丁和线条处理所有内容。
以下是我考虑过的选项:
1)使用绘制数据,隐藏多余的元素(使用ax.axes.get_xaxis().set_visible(False)等),然后绘制自己的轴(使用、
3个回答

2

考虑到你想要做的事情,选项#2可能是最简单的。因此,您将保持直角坐标系,将函数从极坐标转换为直角坐标,并使用plot()绘制它(这比使用`Line2D'更容易)。

将极坐标函数转换为直角坐标函数可以通过以下方式完成:

def polar_to_rect(theta, r):
    return (r*cos(theta), r*sin(theta))

图表可以使用以下方式完成:

def my_polar(theta, r, *args, **kwargs):
    """
    theta, r -- NumPy arrays with polar coordinates.
    """
    rect_coords = polar_to_rect(theta, r)
    pyplot.plot(rect_coords[0], rect_coords[1], *args, **kwargs)
    # You can customize the plot with additional arguments, or use `Line2D` on the points in rect_coords.

确实有效,谢谢。不过出于好奇,有人知道我如何使用Matplotlib的变换支持来避免手动极坐标转换吗? - Roger
@Roger。据我所知,Transform支持线性操作,而这不是线性操作。 - Mad Physicist

0

0
关于您在使用matplotlib转换方面的评论...我使用了以下方法将极坐标图转换为多边形,以便在我的笛卡尔/矩形坐标轴上绘制。
import matplotlib.pyplot as plt

polarPlot = plt.subplot(111, polar = True)
# Create some dummy polar plot data
polarData = np.ones((360,2))
polarData[:,0] = np.arange(0, np.pi, np.pi/360) * polarData[:,0]
# Use the polar plot axes transformation into cartesian coordinates
cartesianData = polarPlot.transProjection.transform(polarData)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接