2
我有一些代码来动画matplotlib中的散点图,一切运行平稳,除了我最后有两个输出图。一个包含所需的动画,而另一个则为空白。matplotlib散点图动画中的两个输出图
虽然这可能是一个简单的问题,但我不明白为什么,也不知道为什么我会得到两张图。任何人都可以看到什么给我的“假”空图吗? 干杯。约
import math, numpy, time, matplotlib, pyvisa
from pyvisa import visa
from matplotlib import pyplot, animation
import os.path
class Realtime_measurement_and_scatter_plot:
def __init__(......):
self.animaiton = animation.FuncAnimation(self.figure, self.take_new_data_and_update_graph, init_func=self.initialise_graph, frames = self.number_of_measurements, interval=100, blit=False)
def initialise_graph(self):
self.figure = matplotlib.pyplot.figure()
self.axes = matplotlib.pyplot.axes()
self.axes.set_title("Realtime Plot")
self.x_data = []
self.y_data = []
self.scatterplot = matplotlib.pyplot.scatter(self.x_data, self.y_data)
return self.scatterplot,
def take_new_data_and_update_graph(self, i):
...
averaged_voltage = numpy.average(measured_voltages)
new_time = float(i) * float(self.time_between_measurements)
self.x_data = numpy.append(self.x_data, averaged_voltage)
self.y_data = numpy.append(self.y_data , new_time)
self.scatterplot = matplotlib.pyplot.scatter(self.x_data, self.y_data)
return self.scatterplot,
animation_instance = Realtime_measurement_and_scatter_plot(1000000, 1 , 1, 6, "Super_FUN_TEST.0",22)
matplotlib.pyplot.show()
请减少此处的代码量。尽管许多人愿意提供帮助,但很少有人愿意通过这个与实际问题无关的代码。请仅张贴演示您的问题所需的_minimum_数量的代码。 – tacaswell
谢谢,代码现在修剪下来! –
它应该仍然是_fuctional_。这看起来很糟糕,因为'__init__'使用了直到'initialize_graph'之前才创建的属性。还有太多的代码(例如,你可以从'take_new_data_and_update_graph'中取出几乎所有的东西。 – tacaswell