[英]scatter polar plot contour
我正在从Excel文件中导入数据,以便绘制出数据的极坐标图。 数据全部收集在极轴的特定区域中,而不是集中点(参见下面的图像,下面的蓝点和代码),我宁愿对整个点组进行轮廓绘制。
有没有一种方法可以在Python中完成? 我尝试使用方法'contourf'(cf stackover flow: matplotlib中的极坐标图-最佳(现代)方法吗? )。 但是我一直坚持下去,我尝试应用它的尝试失败了。 有另一种方法绘制一组点的轮廓吗?
谢谢 !
`
df = pd.read_excel('BW3/BW3StartValues.xlsx')
fig = plt.figure()
ax1 = fig.add_subplot(111, projection='polar')
C = df.C
h = df.h
h = np.radians(h) # convert values of the angle from degrees to radians
ax1.scatter(h,C, s = 5, marker = 'o', color='b')
ax1.set_rmax(60)
plt.show()
这是一个计算数据的凸包的示例(我不知道应该如何计算矩形),并在PolyCollection
帮助下显示该凸包。 由于我没有您的数据,因此我生成了一些随机数据点,但它应该很容易适应。
from matplotlib import pyplot as plt
import numpy as np
from scipy.spatial import ConvexHull
from matplotlib.collections import PolyCollection
fig = plt.figure()
ax1 = fig.add_subplot(111, projection='polar')
#generating some data:
C = np.random.rand(30)*15+40
h = np.random.rand(30)*15+290
h = np.radians(h) # convert values of the angle from degrees to radians
#following scipy example
points = np.concatenate([h,C]).reshape((2,30)).T
hull = ConvexHull(points)
ax1.scatter(h,C, s = 5, marker = 'o', color='b')
#adding the convex hull to ax1 as a PolyCollection:
ax1.add_collection(PolyCollection(
[points[hull.vertices,:]],
edgecolors='r',
facecolors='w',
linewidths=2,
zorder=-1,
))
ax1.set_rmax(60)
plt.show()
如果已经计算出矩形,则可以不进行凸包计算,而从那里生成PolyCollection
。 注意我用来创建PolyCollection
的**kwargs
。 尤其是zorder
很重要,否则多边形将被绘制在这些点的顶部。 结果图如下:
希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.