Source code for optimeed.visualize.fastPlot

from optimeed.visualize.gui.widgets.widget_graphs_visual import widget_graphs_visual
from optimeed.visualize.gui.gui_mainWindow import gui_mainWindow, start_qt_mainloop, stop_qt_mainloop
from optimeed.core.graphs import Data, Graphs
from optimeed.visualize.gui.widgets.graphsVisualWidget.smallGui import guiPyqtgraph
from optimeed.visualize import on_click_measure


[docs]class PlotHolders: def __init__(self): self.curr_g = None self.graphs = Graphs() self.theGraphVisual = widget_graphs_visual(self.graphs, refresh_time=-1, is_light=True) # self.new_plot()
[docs] def add_plot(self, x, y, **kwargs): if self.curr_g is None: self.new_plot() theData = Data(x, y, **kwargs) return self.curr_g, self.graphs.add_trace(self.curr_g, theData)
[docs] def get_wgGraphs(self): return self.theGraphVisual
[docs] def new_plot(self): self.curr_g = self.graphs.add_graph()
[docs] def set_title(self, theTitle, **kwargs): self.theGraphVisual.set_title(self.curr_g, theTitle, **kwargs)
[docs] def reset(self): self.graphs.reset() self.curr_g = None
[docs] def axis_equal(self): self.theGraphVisual.get_graph(self.curr_g).axis_equal()
[docs]class WindowHolders: def __init__(self): self.figures = dict() self.plotHolders = dict() self.currFigure = None
[docs] def set_currFigure(self, currFigure): self.currFigure = currFigure
[docs] def add_plot(self, *args, **kwargs): if self.currFigure is None: self.currFigure = 0 self.new_figure() graph_id, trace_id = self.get_curr_plotHolder().add_plot(*args, **kwargs) return self.currFigure, graph_id, trace_id
[docs] def set_title(self, *args, **kwargs): self.get_curr_plotHolder().set_title(*args, **kwargs)
[docs] def new_figure(self): self.currFigure += 1 self.plotHolders[self.currFigure] = PlotHolders() def actionOnWindowClose(mainWindow, _): # stop_qt_mainloop() mainWindow.close() self.plotHolders[self.currFigure].reset() self.currFigure = None # self.figures[self.currFigure] = self.create_figure() guiPyqtgraph(self.plotHolders[self.currFigure].get_wgGraphs(), actionsOnClick=[on_click_measure()]) the_mainWindow = gui_mainWindow([self.plotHolders[self.currFigure].get_wgGraphs()], size=[1000, 700], actionOnWindowClosed=actionOnWindowClose) the_mainWindow.run(False) self.figures[self.currFigure] = the_mainWindow
[docs] def new_plot(self): self.get_curr_plotHolder().new_plot()
[docs] def show(self): self.figures[self.currFigure].hold()
[docs] def get_curr_plotHolder(self): return self.plotHolders[self.currFigure]
[docs] def get_wgGraphs(self, fig=None): if fig is None: return self.get_curr_plotHolder().get_wgGraphs() return self.plotHolders[fig].get_wgGraphs()
[docs] def get_all_figures(self): return list(self.figures.keys())
[docs] def axis_equal(self): self.get_curr_plotHolder().axis_equal()
[docs]myWindows = WindowHolders()
[docs]def plot(x, y, hold=False, **kwargs): """Plot new trace""" idPlot = myWindows.add_plot(x, y, **kwargs) if hold: show() return idPlot
[docs]def show(): """Show (start qt mainloop) graphs. Blocking""" myWindows.show()
[docs]def figure(numb): """Set current figure""" myWindows.set_currFigure(numb)
[docs]def new_plot(): """Add new plot""" myWindows.new_plot()
[docs]def set_title(theTitle, **kwargs): """Set title of the plot""" myWindows.set_title(theTitle, **kwargs)
[docs]def axis_equal(): myWindows.axis_equal()
[docs]def get_all_figures(): """Get all existing figures""" return myWindows.get_all_figures()
[docs]def get_wgGraphs(fig=None): """Advanced option. :return: :class:`~optimeed.visualize.gui.widgets.widget_graphs_visual.widget_graphs_visual` """ return myWindows.get_wgGraphs(fig)