Custom Spider chart->在matplotlib中的极坐标图上显示曲线,而不是点之间的线

问题描述 投票:2回答:1

我已经测量了不同产品在不同角度位置的位置(在完整旋转中,以60度为步长的6个值)。我要使用极坐标图,而不是在0和360是同一点的笛卡尔图上表示我的值。]

使用matplotlib,我得到了蜘蛛图类型图,但我想避免点之间的直线以及它们之间的显示和外推值。我有一个不错的解决方案,但我希望有一个不错的“单一衬里”,我可以用它来对某些点进行更逼真的表示或更好的切线处理。

有人在下面改进我的代码吗?

# Libraries
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

# Some data to play with
df = pd.DataFrame({'measure':[10, -5, 15,20,20, 20,15,5,10], 'angle':[0,45,90,135,180, 225, 270, 315,360]})

# The few lines I would like to avoid...
angles = [y/180*np.pi for x in [np.arange(x, x+45,5) for x in df.angle[:-1]] for y in x]
values = [y for x in [np.linspace(x, df.measure[i+1], 10)[:-1] for i, x in enumerate(df.measure[:-1])] for y in x]
angles.append(360/180*np.pi)
values.append(values[0])

# Initialise the spider plot
ax = plt.subplot(polar=True)

# Plot data
ax.plot(df.angle/180*np.pi, df['measure'], linewidth=1, linestyle='solid', label="Spider chart")
ax.plot(angles, values, linewidth=1, linestyle='solid', label='what I want')
ax.legend()

# Fill area
ax.fill(angles, values, 'b', alpha=0.1)

plt.show()

结果如下,我想要类似于橙色线的样条,以避免我当前得到的尖角

looking for a smooth curb on a polar graph

我已经测量了不同产品在不同角度位置的位置(在完整旋转中,以60度为步长的6个值)。而不是在笛卡尔图上表示我的值,其中...

python matplotlib polar-coordinates
1个回答
0
投票

我有一个解决方案,是其他解决方案的拼凑而成。它需要清理和优化,但是可以完成工作!

© www.soinside.com 2019 - 2024. All rights reserved.