Skip to content

Instantly share code, notes, and snippets.

@gwbischof
Created March 16, 2023 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gwbischof/afe58eee621b646cf1ed4b74c65b1b98 to your computer and use it in GitHub Desktop.
Save gwbischof/afe58eee621b646cf1ed4b74c65b1b98 to your computer and use it in GitHub Desktop.
ophyd device plotter
def plot_ophyd_device(device, dont_plot={'ramp_rate'}):
'''
Plot all of the signals of an ophyd device.
There is probably some inaccuracy of the timestamps.
Simple implementation.
'''
history = {signal: [getattr(device, signal).get()]
for signal in set(device.component_names) - dont_plot}
history['timestamp'] = [time.time()]
print(set(device.component_names) - dont_plot)
def update(i):
history['timestamp'].append(time.time())
x = history['timestamp']
plt.cla()
for signal in set(device.component_names) - dont_plot:
history[signal].append(getattr(device, signal).get())
plt.plot(x, history[signal])
plt.xlabel('time')
plt.ylabel('value')
plt.title(device.name)
plt.gcf().autofmt_xdate()
plt.tight_layout()
ani = FuncAnimation(plt.gcf(), update, 1000)
plt.tight_layout()
plt.show(block=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment