Commit 551f7cab authored by AG-BLUHM-38\Flash's avatar AG-BLUHM-38\Flash
Browse files

Add function to dynamically update plots

parent ecf285f7
......@@ -10,7 +10,7 @@ import pandas as pd
import numpy as np
__all__ = ["plot_2d_dataframe", "rwth_color_cycle"]
__all__ = ["plot_2d_dataframe", "cycle_plots", "rwth_color_cycle", "update_plot"]
_color_names = ['blue', 'magenta', 'green', 'orange', 'teal', 'maygreen',
'red', 'purple', 'violet', 'bordeaux', 'petrol', 'yellow']
......@@ -157,6 +157,35 @@ def plot_2d_dataframe(df: pd.DataFrame,
return ax
def update_plot(handle, data):
"""Update a plot.
Parameters
----------
handle: matplotlib data handle
The plot object that is updated. For instance, a lines.Line2D or
image.AxesImage object.
*data: Sequence
New data to plot.
- for line plots: [xdata, ydata]
- for image plots: imdata (m x n array)
"""
handle.set_data(data)
if hasattr(handle, 'colorbar'):
handle.colorbar.set_array(data)
handle.colorbar.changed()
handle.colorbar.autoscale()
handle.colorbar.draw_all()
# Rescale
handle.axes.relim()
handle.axes.autoscale_view()
# We need to draw *and* flush
handle.figure.canvas.draw()
handle.figure.canvas.flush_events()
def cycle_plots(plot_callback, *args,
fig: plt.Figure = None, ax: plt.Axes = None, **kwargs) -> Tuple[plt.Figure, plt.Axes]:
"""Call plot_callback(fig, ax, curr_pos, *args, **kwargs) on each left/right arrow key press.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment