Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/321.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_Plot_Polar Coordinates_Radial - Fatal编程技术网

Python matplotlib:具有';缺口';

Python matplotlib:具有';缺口';,python,matplotlib,plot,polar-coordinates,radial,Python,Matplotlib,Plot,Polar Coordinates,Radial,有没有一种方法可以在r=0或r=U外缘的位置用“凹口”装饰我的极坐标/径向坐标图?下面是一个例子。我所说的“凹口”是指在原点和绘图边缘的红色和蓝色线条。 下面的代码可用于生成极坐标图 import numpy as np import matplotlib.pyplot as plt data = [-121,87,118,87,109,-139,-112,115,153,-109,-106,-92,75,-98,103,-89, 152,114,77,-109,77,107,-77

有没有一种方法可以在r=0或r=U外缘的位置用“凹口”装饰我的极坐标/径向坐标图?下面是一个例子。我所说的“凹口”是指在原点和绘图边缘的红色和蓝色线条。

下面的代码可用于生成极坐标图

import numpy as np
import matplotlib.pyplot as plt

data = [-121,87,118,87,109,-139,-112,115,153,-109,-106,-92,75,-98,103,-89,
    152,114,77,-109,77,107,-77,106,-158,-71,-166,97,144,-166,138,39,130,
    -71,-76,-82,128,74,-47,94,-119,130,76,-86,-85,108,-78,-96,-113,82,
    127,-168,72,83,-61,-99,-83,-130,-69,43]

r = np.arange(0, len(data))
ax = plt.subplot(111,polar=True)
ax.scatter(data,r)
plt.show()

您可以使用注释:

plt.annotate(' ',xy=(0, 0),  # theta, radius
            xytext = (-np.pi/10,len(data)/6.),
            textcoords='data',
            arrowprops=dict(facecolor='red', shrink=0.05))
plt.annotate(' ',xy=(np.pi/4.2, 1.355*max(r)),  # theta, radius
            xytext = (np.pi/4.2, 1.2*max(r)),
            textcoords='data',
            arrowprops=dict(facecolor='blue', shrink=0.05))
或者您可以使用绘图:

rmax = ax.get_rmax()
theta_startstop = [2*[-np.pi/10],2*[np.pi/4.2]]
r_startstop = [[0,0.1*rmax],[0.9*rmax,rmax]]
notchcolor = ['red', 'blue']
for i in range(len(r_startstop)):
    ax.plot(np.array(theta_startstop[i]), np.array(r_startstop[i]),
            lw=3, c=notchcolor[i])
ax.set_rmax(rmax)
结果将是: