Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/357.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 混合Matplotlib面片和极坐标图?_Python_Matplotlib - Fatal编程技术网

Python 混合Matplotlib面片和极坐标图?

Python 混合Matplotlib面片和极坐标图?,python,matplotlib,Python,Matplotlib,我试图用极坐标绘制一些数据,但我不想要Matplotlibpolar()函数得到的标准刻度、标签、轴等。我想要的只是原始图,其他什么都没有,因为我正在用手工绘制的面片和线条处理一切 以下是我考虑过的选项: 1) 使用polar()绘制数据,隐藏多余的内容(使用ax.axes.get_xaxis().set_visible(False)等),然后绘制我自己的轴(使用Line2D,Circle等)。问题是当我调用polar()并随后添加一个圆面片时,它是在极坐标中绘制的,最终看起来像一个无穷大的符号

我试图用极坐标绘制一些数据,但我不想要Matplotlib
polar()
函数得到的标准刻度、标签、轴等。我想要的只是原始图,其他什么都没有,因为我正在用手工绘制的面片和线条处理一切

以下是我考虑过的选项:

1) 使用
polar()
绘制数据,隐藏多余的内容(使用
ax.axes.get_xaxis().set_visible(False)
等),然后绘制我自己的轴(使用
Line2D
Circle
等)。问题是当我调用
polar()
并随后添加一个
面片时,它是在极坐标中绘制的,最终看起来像一个无穷大的符号。此外,缩放似乎不适用于
polar()
函数

2) 跳过
polar()。问题是我不知道如何在极坐标系下绘制Line2D,也不知道如何使用变换来实现这一点


你知道我该怎么做吗?

要删除记号和标签,请尝试使用

`matplotlib.pyplot.tick_params(axis='both', which='both', length=0, width=0, labelbottom = False, labeltop = False, labelleft = False, labelright = False)`

你的选择#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.
可通过以下方式进行绘图:

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变换的评论…我使用以下方法将极坐标图转换为可以在笛卡尔/矩形轴上绘制的多边形

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)

这确实有效,谢谢。不过出于好奇,有人知道我如何使用Matplotlib的转换支持来避免手动极坐标转换吗?@Roger。据我所知,Transform支持线性运算,但事实并非如此。