我测量了不同产品在不同角度位置的位置(在完整旋转过程中以 60 度为步长的 6 个值)。我想使用极坐标图,而不是在笛卡尔图上表示我的值(其中 0 和 360 是同一点)。
With 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()
结果如下,我想要类似于橙色线的东西,带有某种样条线,以避免我目前得到的尖角