在以下脚本中,创建了一个绘图窗口,plot.update
正确传递给import sys
import time
import numpy
from numpy import pi
import rx
from rx.concurrency import QtScheduler
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
class DemoData:
def __init__(self, window, steps):
def signal(t):
omega = 5
return numpy.sin(2*pi*omega*t) + numpy.random.random()
self.stream = rx.Observable.range(
0, steps
).map(
signal
).buffer_with_count(
window, 1
)
class UpdatingPlot:
def __init__(self):
self.plot = pg.plot()
self.curve = self.plot.plot()
def update(self, values):
self.curve.setData(values)
def main():
app = QtGui.QApplication([])
scheduler = QtScheduler(QtCore)
window, steps = 50, 100
data = DemoData(window, steps)
plot = UpdatingPlot()
data.stream.subscribe_on(scheduler=scheduler).subscribe(plot.update)
sys.exit(app.exec_())
if __name__ == '__main__':
main()
。但是,情节没有更新。我做错了什么?
oSheet.Range("F" & j + 1).Formula = "=SUBTOTAL(9,F" & summaryPosition & ":F" & j & ")"
oSheet.Range("G" & j + 1).Formula = "=SUBTOTAL(9,G" & summaryPosition & ":G" & j & ")"
oSheet.Range("H" & j + 1).Formula = "=SUBTOTAL(9,H" & summaryPosition & ":H" & j & ")"
oSheet.Range("I" & j + 1).Formula = "=SUBTOTAL(9,I" & summaryPosition & ":I" & j & ")"
oSheet.Range("J" & j + 1).Formula = "=SUBTOTAL(9,J" & summaryPosition & ":J" & j & ")"
答案 0 :(得分:1)
这不能解决您的问题,但它可能会解决您的需求。您可以使用包joystick
,使用pip install joystick
进行安装。它旨在提供实时和交互式的绘图框架。
以下是使用它的示例。它创建了一个图形框架,可以“听”'并显示您的正弦函数作为时间的函数;每0.2秒添加一个新数据点。
import joystick as jk
import numpy as np
import time
class DemoData(jk.Joystick):
# initialize the infinite loop and callit decorators so they can auto-
# register methods they decorate
_infinite_loop = jk.deco_infinite_loop()
_callit = jk.deco_callit()
@_callit('before', 'init')
def _init_data(self, *args, **kwargs):
# Function automatically called at initialization, thanks to the
# decorator
self.tdata = np.array([]) # time x-axis
self.ydata = np.array([]) # data y-axis
self.omega = 5
@_callit('after', 'init')
def _build_frames(self, *args, **kwargs):
# Function automatically called at initialization, thanks to the
# decorator.
# Creates a graph frame
self.mygraph = self.add_frame(
jk.Graph(name="DemoData", size=(500, 500), pos=(50, 50),
fmt="go-", xnpts=50, freq_up=7, bgcol="w",
xylim=(None,None,-1.1,2.1), xlabel='t', ylabel='sine'))
@_callit('before', 'start')
def _set_t0(self):
# initialize t0 at start-up
self._t0 = time.time()
@_infinite_loop(wait_time=0.2)
def _get_data(self):
# This method will automatically be called with simulation start
# (t.start()), and looped every 0.2 in a separate thread as long as
# the simulation runs (running == True)
# It generates new data and pushes it to the frame.
# concatenate data on the time x-axis
timestamp = time.time() - self._t0
self.tdata = jk.add_datapoint(self.tdata,
timestamp,
xnptsmax=self.mygraph.xnptsmax)
new_y_data = np.sin(2*np.pi*self.omega*timestamp) + np.random.random()
self.ydata = jk.add_datapoint(self.ydata,
new_y_data,
xnptsmax=self.mygraph.xnptsmax)
# push new data to the graph
self.mygraph.set_xydata(np.round(self.tdata, 1), self.ydata)
d = DemoData()
d.start()
...
d.stop()