1
matplotlib의 내장 애니메이션 모듈을 사용하여 측정 된 데이터를 "재생"할 수있는 Python/Matplotlib을 사용하여 레이더 차트를 만들려고합니다. 데이터 세트가 통과 할 때 데이터 포인트가 각 축을 따라 이동하기를 원합니다. 데이터를 읽거나 차트를 업데이트하는 데 문제가 있거나 이런 예를 찾을 수 없습니다.Python 애니메이션 레이더 차트
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from math import pi
class SubplotAnimation(animation.TimedAnimation):
def __init__(self, data):
self.data = data
fig = plt.figure()
ax = fig.add_subplot(111, projection='polar')
# Figure definition
cat = ['A', 'B', 'C', 'D', 'E']
values = [10, 10, 10, 10, 10]
N = len(cat)
x_as = [n/float(N) * 2 * pi for n in range(N)]
# Because our chart will be circular we need to append a copy of
# the first value of each list at the end of each list with data
values += values[:1]
x_as += x_as[:1]
plt.rc('axes', linewidth=0.5, edgecolor='#888888') # Set color of axes
# Create polar plot
ax = plt.subplot(111, projection='polar')
# Set clockwise rotation. That is:
ax.set_theta_offset(pi/2)
ax.set_theta_direction(-1)
# Set position of y-labels
ax.set_rlabel_position(0)
# Set color and linestyle of grid
ax.xaxis.grid(True, color="#888888", linestyle='solid', linewidth=0.5)
ax.yaxis.grid(True, color="#888888", linestyle='solid', linewidth=0.5)
# Set number of radial axes and remove labels
plt.xticks(x_as[:-1], [])
# Set yticks
plt.yticks([20, 40, 60, 80, 100], ["20", "40", "60", "80", "100"])
# Set axes limits
plt.ylim(0, 100)
# Draw ytick labels to make sure they fit properly
for i in range(N):
angle_rad = i/float(N) * 2 * pi
if angle_rad == 0:
ha, distance_ax = "center", 10
elif 0 < angle_rad < pi:
ha, distance_ax = "left", 1
elif angle_rad == pi:
ha, distance_ax = "center", 1
else:
ha, distance_ax = "right", 1
ax.text(angle_rad, 100 + distance_ax, cat[i], size=10,
horizontalalignment=ha, verticalalignment="center")
animation.TimedAnimation.__init__(self, fig, interval=25, blit=True)
def new_frame_seq(self):
return iter(range(len(self.data)))
def _draw_frame(self, framedata):
ax.plot(ax, framedata)
testdata = [[10, 20, 30, 40, 50],
[10, 20, 30, 40, 50],
[40, 50, 60, 70, 80],
[40, 50, 60, 70, 80],
[50, 60, 70, 80, 90]]
ani = SubplotAnimation(testdata)
plt.show()
이 작품을 만드는 방법에 대한 모든 팁이 크게 감사합니다 :
난 당신에게 내가 달성하기 위해 노력하고있는 무슨의 아이디어를 줄 것이다 코드의 조각을 첨부!
이 주셔서 너무 감사합니다! 나는 그것이 결국 내가 의도했던 방식대로 작동하게했다 :-) – esvendsen
위대한. 따라서이 질문에 답하면 (수락) (https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) 수 있습니다. 대답이 마음에 들면, (upvote) (https://meta.stackexchange.com/questions/173399/how-to-upvote-on-stack-overflow) 그것을 할 수 있습니다 (이것은 15 점에 도달하면 계산됩니다). 그렇게하지 않았다면 [둘러보기]를 선택하십시오. – ImportanceOfBeingErnest