Last active
March 21, 2019 10:00
-
-
Save Tillsten/6dfd20c511475b0a4188c0ad54e4f450 to your computer and use it in GitHub Desktop.
Vispy updating plot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import numpy as np | |
import vispy | |
from vispy import scene, app | |
print(vispy.__version__) | |
canvas = scene.SceneCanvas(keys='interactive', size=(600, 600), show=True) | |
canvas.measure_fps() | |
grid = canvas.central_widget.add_grid(margin=10) | |
grid.spacing = 0 | |
title = scene.Label("Plot Title", color='white') | |
title.height_max = 40 | |
grid.add_widget(title, row=0, col=0, col_span=2) | |
yaxis = scene.AxisWidget(orientation='left', | |
axis_label='Y Axis', | |
axis_font_size=20, | |
axis_label_margin=50, | |
tick_label_margin=5) | |
yaxis.width_max = 80 | |
grid.add_widget(yaxis, row=1, col=0) | |
xaxis = scene.AxisWidget(orientation='bottom', | |
axis_label='X Axis', | |
axis_font_size=20, | |
axis_label_margin=50, | |
tick_label_margin=5) | |
xaxis.height_max = 80 | |
grid.add_widget(xaxis, row=2, col=1) | |
right_padding = grid.add_widget(row=1, col=2, row_span=1) | |
right_padding.width_max = 50 | |
view = grid.add_view(row=1, col=1, border_color='white') | |
data = np.zeros((1000, 2)) | |
plot = scene.Line(data, parent=view.scene) | |
view.camera = 'panzoom' | |
plot.set_data(data, width=4, color='g') | |
xaxis.link_view(view) | |
yaxis.link_view(view) | |
import time | |
t0 = time.time() | |
def update(up): | |
global data | |
data[:, 0] = np.linspace(0, 10, 1000)+time.time()-t0 | |
data[:, 1] = np.sin(data[:, 0])+0.4*np.random.normal(size=(1000)) | |
plot.set_data(data) | |
view.camera.set_range(y=(data[:, 1].max(), data[:, 1].min()), x=(data[:, 0].max(), data[:, 0].min())) | |
t = app.Timer() | |
t.connect(update) | |
t.start() | |
if __name__ == '__main__' and sys.flags.interactive == 0: | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment