Python 雷达图连接第一个点和最后一个点
Python radar plot join first and last points
我正在尝试绘制雷达图。在将第一个点和最后一个点连接在一起时,我遇到了麻烦。目前结果如下所示:
看来50分没有加入,我不明白为什么。
我正在将点连接在一起,我想我已经确定它们会用这段代码连接在一起:
t1=np.concatenate([l1,r1,l2])
t1 += t1[:0]
theta += theta[:0]
然而这returns一条消息ValueError: operands could not be broadcast together with shapes (101,) (0,) (101,)
我用来绘图的代码是:
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection='radar')
ax.plot(theta, t1, color='r')
ax.set_varlabels(labels)
for label in ax.get_xticklabels()[::2]:
label.set_visible(False)
plt.savefig("radar.png", dpi=100)
我该如何解决这个错误?
我可以举个例子。据我了解,您有一个类似(但规模更大)的问题,如下所示,我举了两个例子。
- 补充说明:
plot([x1,x2],[y1,y2])
将绘制 (x1,y1)
,并绘制一条线将其连接到点 (x2,y2)
。因此,您必须按照以下顺序放置您的积分:[x1, x2, x3, ...., xn, x1]
和 [y1, y2, y3, ...., yn, y1]
以创建 'the loop'.
这样可以吗?
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure();
ax = fig.add_subplot(1, 1, 1, projection='polar');
theta1 = [0, 0.5*np.pi, 0];
r1 = [1, 1, 0];
ax.plot(theta1, r1, color='r');
plt.show();
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure();
ax = fig.add_subplot(1, 1, 1, projection='polar');
theta1 = [0, 0.5*np.pi, 0, 0];
r1 = [1, 1, 0, 1];
ax.plot(theta1, r1, color='r');
plt.show();
我正在尝试绘制雷达图。在将第一个点和最后一个点连接在一起时,我遇到了麻烦。目前结果如下所示:
看来50分没有加入,我不明白为什么。
我正在将点连接在一起,我想我已经确定它们会用这段代码连接在一起:
t1=np.concatenate([l1,r1,l2])
t1 += t1[:0]
theta += theta[:0]
然而这returns一条消息ValueError: operands could not be broadcast together with shapes (101,) (0,) (101,)
我用来绘图的代码是:
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection='radar')
ax.plot(theta, t1, color='r')
ax.set_varlabels(labels)
for label in ax.get_xticklabels()[::2]:
label.set_visible(False)
plt.savefig("radar.png", dpi=100)
我该如何解决这个错误?
我可以举个例子。据我了解,您有一个类似(但规模更大)的问题,如下所示,我举了两个例子。
- 补充说明:
plot([x1,x2],[y1,y2])
将绘制(x1,y1)
,并绘制一条线将其连接到点(x2,y2)
。因此,您必须按照以下顺序放置您的积分:[x1, x2, x3, ...., xn, x1]
和[y1, y2, y3, ...., yn, y1]
以创建 'the loop'.
这样可以吗?
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure();
ax = fig.add_subplot(1, 1, 1, projection='polar');
theta1 = [0, 0.5*np.pi, 0];
r1 = [1, 1, 0];
ax.plot(theta1, r1, color='r');
plt.show();
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure();
ax = fig.add_subplot(1, 1, 1, projection='polar');
theta1 = [0, 0.5*np.pi, 0, 0];
r1 = [1, 1, 0, 1];
ax.plot(theta1, r1, color='r');
plt.show();