def _update_curve(self, idx, f_axes, c, x, y, data, title): if f_axes.num_child() == 0: obj = FigPlot([0], [0]) f_axes.add_child('xslice_plot1', obj) obj = FigPlot([0], [0]) f_axes.add_child('xslice_plot2', obj) f_axes.realize() j = 0 for name, child in f_axes.get_children(): if (isinstance(child, FigPlot)): if j == idx: child.setvar('x', data[0]) child.setvar('y', data[1]) child.set_suppress(False) child.reset_artist() a = child._artists[0] a.set_color(c) break else: j = j + 1 f_axes.adjust_axes_range() v = f_axes.get_title(f_axes._artists[0]) v[0] = title v = f_axes.set_title(v, f_axes._artists[0]) f_axes.set_bmp_update(False)
def generate_artist(self): FigPlot.generate_artist(self) container = self.get_container() a = self._artists[0] x = a.get_xdata() y = a.get_ydata() vm = self.getp('marked_point') if vm is not None: if self._mark_a is not None: self._mark_a.remove() self._mark_a = None a3 = container.plot(x[vm].copy(), y[vm].copy(), marker='o', color='k', linestyle='None', markerfacecolor='k', markeredgecolor='k', markersize=6, scalex=False, scaley=False) self._mark_a = a3[0] idx = np.where([not xx for xx in self.getp('enabled_point')])[0] if self._enable_a is not None: self._enable_a.remove() self._enable_a = None if idx.size == 0: return marker = a.get_marker() fc = 'white' ec = a.get_markeredgecolor() ms = a.get_markersize() a2 = container.plot(x[idx].copy(), y[idx].copy(), marker=marker, color='k', linestyle='None', markerfacecolor=fc, markeredgecolor=ec, markersize=ms, scalex=False, scaley=False) self._enable_a = a2[0]
def canvas_menu(self): m = [ ('Add Point', self.onAddPoint, None), ] if self._figc_hit != -1: if self.getp('enabled_point')[self._figc_hit]: m = m + [ ('Delete point', self.onDelPoint, None), ('Edit point', self.onEditPoint, None), ('Disable point', self.onDisablePoint, None), ] else: m = m + [ ('Delete point', self.onDelPoint, None), ('Edit point', self.onEditPoint, None), ('Enable point', self.onEnablePoint, None), ] vm = self.get_mark_data() if vm[self._figc_hit]: m = m + [ ('Unmark point', self.onUnmarkPoint, None), ('Reset mark', self.onResetMark, None), ('Export mark', self.onExportMark, None), ] else: m = m + [ ('Mark point', self.onMarkPoint, None), ('Reset mark', self.onResetMark, None), ('Export mark', self.onExportMark, None), ] return m + FigPlot.canvas_menu(self)
def __new__(cls, *args,**kargs): draggable, kargs = ProcessKeywords(kargs, 'draggable', True) enabled_point, kargs = ProcessKeywords(kargs, 'enabled_point', 'all') obj = FigPlot.__new__(cls, *args,**kargs) if obj is not None: obj.setvar('draggable', draggable) if not obj.hasvar('enabled_point'): obj.setvar('enabled_point', enabled_point) return obj
def del_artist(self, artist=None, delall=False): if self._enable_a is not None: self._enable_a.remove() self._enable_a = None if self._mark_a is not None: self._mark_a.remove() self._mark_a = None return FigPlot.del_artist(self, artist=artist, delall=delall)
def __new__(cls, *args, **kargs): draggable, kargs = ProcessKeywords(kargs, 'draggable', True) enabled_point, kargs = ProcessKeywords(kargs, 'enabled_point', 'all') obj = FigPlot.__new__(cls, *args, **kargs) if obj is not None: obj.setvar('draggable', draggable) if not obj.hasvar('enabled_point'): obj.setvar('enabled_point', enabled_point) return obj
def generate_artist(self): FigPlot.generate_artist(self) container=self.get_container() a = self._artists[0] x=a.get_xdata() y=a.get_ydata() vm = self.getp('marked_point') if vm is not None: if self._mark_a is not None: self._mark_a.remove() self._mark_a = None a3 = container.plot(x[vm].copy(), y[vm].copy(), marker='o', color='k', linestyle='None', markerfacecolor='k', markeredgecolor='k', markersize = 6, scalex=False, scaley=False) self._mark_a = a3[0] idx = np.where([not xx for xx in self.getp('enabled_point')])[0] if self._enable_a is not None: self._enable_a.remove() self._enable_a = None if idx.size == 0: return marker = a.get_marker() fc = 'white' ec = a.get_markeredgecolor() ms = a.get_markersize() a2 = container.plot(x[idx].copy(), y[idx].copy(), marker=marker, color='k', linestyle='None', markerfacecolor=fc, markeredgecolor=ec, markersize = ms, scalex=False, scaley=False) self._enable_a = a2[0]
def picker_a(self, artist, evt): hit = False self._figc_hit = -1 self._figc_hit_pos = (evt.xdata, evt.ydata) axes = artist.axes if axes is None: return False, {} x = artist.get_xdata() y = artist.get_ydata() for k, pd in enumerate(axes.transData.transform(np.transpose(np.vstack((x, y))))): if (abs(evt.x - pd[0]) < 5 and abs(evt.y - pd[1]) < 5): hit = True self._figc_hit = k break if hit: return True, {'child_artist':artist} return FigPlot.picker_a(self, artist, evt)
def picker_a(self, artist, evt): hit = False self._figc_hit = -1 self._figc_hit_pos = (evt.xdata, evt.ydata) axes = artist.axes if axes is None: return False, {} x = artist.get_xdata() y = artist.get_ydata() for k, pd in enumerate( axes.transData.transform(np.transpose(np.vstack((x, y))))): if (abs(evt.x - pd[0]) < 5 and abs(evt.y - pd[1]) < 5): hit = True self._figc_hit = k break if hit: return True, {'child_artist': artist} return FigPlot.picker_a(self, artist, evt)
def canvas_menu(self): m = [('Add Point', self.onAddPoint, None),] if self._figc_hit != -1: if self.getp('enabled_point')[self._figc_hit]: m = m + [('Delete point', self.onDelPoint, None), ('Edit point', self.onEditPoint, None), ('Disable point', self.onDisablePoint, None),] else: m = m + [('Delete point', self.onDelPoint, None), ('Edit point', self.onEditPoint, None), ('Enable point', self.onEnablePoint, None),] vm = self.get_mark_data() if vm[self._figc_hit]: m = m+ [ ('Unmark point', self.onUnmarkPoint, None), ('Reset mark', self.onResetMark, None), ('Export mark', self.onExportMark, None),] else: m = m + [('Mark point', self.onMarkPoint, None), ('Reset mark', self.onResetMark, None), ('Export mark', self.onExportMark, None),] return m + FigPlot.canvas_menu(self)
def onCopyPath(self, event): from ifigure.mto.fig_plot import FigPlot from ifigure.mto.fig_fill import FigFill if self._hit_path is not None: canvas = event.GetEventObject() v = self._hit_path.vertices if self.getp('FillMode'): obj = FigFill(v[:, 0], v[:, 1]) else: obj = FigPlot(v[:, 0], v[:, 1], 'k') ax = self.get_figaxes() name = ax.get_next_name('Contour_path') ax.add_child(name, obj) obj.realize() ax.set_bmp_update(False) canvas.draw() artists = [weakref.ref(obj._artists[0])] h = [UndoRedoAddRemoveArtists(artists=artists, mode=0)] window = canvas.GetTopLevelParent() GlobalHistory().get_history(window).make_entry( h, menu_name='add path plot')
def postprocess_data( self, ana, viewer, color_order=['red', 'blue', 'yellow'], ): def set_auto_color_to_color(kargs, name, col): if (not name in kargs) or (kargs[name] == 'auto'): kargs[name] = col return kargs from ifigure.mto.fig_plot import FigPlot, TimeTrace, StepPlot from ifigure.mto.fig_contour import FigContour from ifigure.mto.fig_image import FigImage from ifigure.mto.fig_surface import FigSurface from ifigure.mto.fig_axline import FigAxline from ifigure.mto.fig_axspan import FigAxspan from ifigure.mto.fig_text import FigText self._color_order = color_order dprint2('process_data', self) if ana.skipped: if ana.do_title: self.process_title(ana) return True if (self.isempty() and not self.get_figaxes().isempty() and not self._suppress): self.generate_artist() # app = self.get_app() # ax = self.get_container() # fig_ax = ax.figobj ishot = ana.ishot self._analysis_flag[ishot] = False col = color_order[ishot % len(color_order)] for x in range(ishot - self.num_child() + 1): plot_options = self.getvar('plot_options') if self._plot_type == 'plot': kargs = plot_options['plot'][1].copy() kargs = set_auto_color_to_color(kargs, 'color', col) kargs = set_auto_color_to_color(kargs, 'markerfacecolor', col) kargs = set_auto_color_to_color(kargs, 'markeredgecolor', col) obj = FigPlot([0], [0], *(plot_options['plot'][0]), **kargs) elif self._plot_type == 'timetrace': kargs = plot_options['timetrace'][1].copy() kargs = set_auto_color_to_color(kargs, 'color', col) kargs = set_auto_color_to_color(kargs, 'markerfacecolor', col) kargs = set_auto_color_to_color(kargs, 'markeredgecolor', col) obj = TimeTrace([0], [0], *(plot_options['timetrace'][0]), **kargs) elif self._plot_type == 'stepplot': kargs = plot_options['stepplot'][1].copy() kargs = set_auto_color_to_color(kargs, 'color', col) kargs = set_auto_color_to_color(kargs, 'markerfacecolor', col) kargs = set_auto_color_to_color(kargs, 'markeredgecolor', col) obj = StepPlot([0], [0], *(plot_options['stepplot'][0]), **kargs) elif self._plot_type == 'contour': obj = FigContour([0, 1], [0, 1], np.arange(4).reshape(2, 2), *(plot_options['contour'][0])) elif self._plot_type == 'image': obj = FigImage(np.zeros([2, 2])) elif self._plot_type == 'surface': obj = FigSurface(np.zeros([2, 2])) elif self._plot_type == 'axspan': obj = FigAxspan([0, 1]) elif self._plot_type == 'axline': obj = FigAxline(np.zeros([1])) elif self._plot_type == 'text': obj = FigText(0, 0, '') name = self._plot_type + str(self.num_child() + 1) self.add_child(name, obj) obj.set_container_idx(self._container_idx) obj.set_suppress(True) if self.get_script_local(): txt = self.make_script(ana.shot, short=True) debug_mode = viewer.debug_mode if txt is not None: try: vars = viewer.get_globals_for_figmds(ana.shot) # print vars for key in vars: ana.result[key] = vars[key] for key in viewer.startup_values: ana.result[key] = viewer.startup_values[key] ana.result['shot'] = ana.shot if self.getvar('posvars') is not None: a = {} b = {} exec self.getvar('posvars') in a, b for key in b: ana.result[key] = b[key] filepath = os.path.join(self.owndir(), script_file_name) from ifigure.widgets.debugger_core import get_breakpoint code = compile(txt, filepath, 'exec') if (len(get_breakpoint(filepath)) != 0 and debug_mode): app = wx.GetApp().TopWindow se = app.script_editor import threading if not se.CheckDebuggerStatus(): se.QueueSEDRequest(code, viewer.g, ana.result, filepath) # print threading.current_thread().name # wx.Yield() # time.sleep(3) else: se.RunSED(code, viewer.g, ana.result, filepath) else: exec code in viewer.g, ana.result except: dprint1('error occured when processing data by script') print( 'error occured when processing data by following script' ) print('#####') print(txt) print('#####') print(traceback.format_exc()) self.change_suppress(True, self.get_child(ishot)) return False if ana.do_title: self.process_title(ana) if self._plot_type == 'plot': self._update_plot(ana, ishot) #, color_order) elif self._plot_type == 'timetrace': self._update_plot(ana, ishot) #, color_order) elif self._plot_type == 'stepplot': self._update_plot(ana, ishot) #, color_order) elif self._plot_type == 'contour': self._update_contour(ana, ishot) elif self._plot_type == 'image': self._update_image(ana, ishot) elif self._plot_type == 'surface': self._update_surface(ana, ishot) elif self._plot_type == 'axspan': self._update_axspan(ana, ishot) elif self._plot_type == 'axline': self._update_axline(ana, ishot) elif self._plot_type == 'text': self._update_text(ana, ishot) obj = self.get_child(idx=ishot) if obj.is_suppress(): return False obj._data_extent = None try: if (self.get_figaxes() is not None): self.get_figaxes().adjust_axes_range() except: dprint1( "failed in adjusting axes at postprocess_data, continuing...") pass return True
def postprocess_data(self, ana, viewer, color_order=['red','blue','yellow'], ): def set_auto_color_to_color(kargs, name, col): if (not name in kargs) or (kargs[name] == 'auto'): kargs[name] = col return kargs from ifigure.mto.fig_plot import FigPlot, TimeTrace, StepPlot from ifigure.mto.fig_contour import FigContour from ifigure.mto.fig_image import FigImage from ifigure.mto.fig_surface import FigSurface from ifigure.mto.fig_axline import FigAxline from ifigure.mto.fig_axspan import FigAxspan from ifigure.mto.fig_text import FigText self._color_order = color_order dprint2('process_data', self) if ana.skipped: if ana.do_title: self.process_title(ana) return True if (self.isempty() and not self.get_figaxes().isempty() and not self._suppress): self.generate_artist() # app = self.get_app() # ax = self.get_container() # fig_ax = ax.figobj ishot = ana.ishot self._analysis_flag[ishot] = False col = color_order[ishot % len(color_order)] for x in range(ishot - self.num_child()+1): plot_options = self.getvar('plot_options') if self._plot_type == 'plot': kargs = plot_options['plot'][1].copy() kargs = set_auto_color_to_color(kargs, 'color', col) kargs = set_auto_color_to_color(kargs, 'markerfacecolor', col) kargs = set_auto_color_to_color(kargs, 'markeredgecolor', col) obj=FigPlot([0],[0], *(plot_options['plot'][0]), **kargs) elif self._plot_type == 'timetrace': kargs = plot_options['timetrace'][1].copy() kargs = set_auto_color_to_color(kargs, 'color', col) kargs = set_auto_color_to_color(kargs, 'markerfacecolor', col) kargs = set_auto_color_to_color(kargs, 'markeredgecolor', col) obj=TimeTrace([0],[0], *(plot_options['timetrace'][0]), **kargs) elif self._plot_type == 'stepplot': kargs = plot_options['stepplot'][1].copy() kargs = set_auto_color_to_color(kargs, 'color', col) kargs = set_auto_color_to_color(kargs, 'markerfacecolor', col) kargs = set_auto_color_to_color(kargs, 'markeredgecolor', col) obj=StepPlot([0],[0], *(plot_options['stepplot'][0]), **kargs) elif self._plot_type == 'contour': obj=FigContour([0,1], [0,1], np.arange(4).reshape(2,2), *(plot_options['contour'][0])) elif self._plot_type == 'image': obj=FigImage(np.zeros([2,2])) elif self._plot_type == 'surface': obj=FigSurface(np.zeros([2,2])) elif self._plot_type == 'axspan': obj=FigAxspan([0,1]) elif self._plot_type == 'axline': obj=FigAxline(np.zeros([1])) elif self._plot_type == 'text': obj=FigText(0, 0, '') name = self._plot_type + str(self.num_child()+1) self.add_child(name, obj) obj.set_container_idx(self._container_idx) obj.set_suppress(True) if self.get_script_local(): txt = self.make_script(ana.shot, short = True) debug_mode = viewer.debug_mode if txt is not None: try: vars = viewer.get_globals_for_figmds(ana.shot) # print vars for key in vars: ana.result[key] = vars[key] for key in viewer.startup_values: ana.result[key] = viewer.startup_values[key] ana.result['shot'] = ana.shot if self.getvar('posvars') is not None: a = {}; b = {} exec self.getvar('posvars') in a, b for key in b: ana.result[key] = b[key] filepath = os.path.join(self.owndir(), script_file_name) from ifigure.widgets.debugger_core import get_breakpoint code = compile(txt, filepath, 'exec') if (len(get_breakpoint(filepath)) != 0 and debug_mode): app = wx.GetApp().TopWindow se = app.script_editor import threading if not se.CheckDebuggerStatus(): se.QueueSEDRequest(code, viewer.g, ana.result, filepath) # print threading.current_thread().name # wx.Yield() # time.sleep(3) else: se.RunSED(code, viewer.g, ana.result, filepath) else: exec code in viewer.g, ana.result except: dprint1('error occured when processing data by script') print('error occured when processing data by following script') print('#####') print(txt) print('#####') print(traceback.format_exc()) self.change_suppress(True, self.get_child(ishot)) return False if ana.do_title: self.process_title(ana) if self._plot_type == 'plot': self._update_plot(ana, ishot)#, color_order) elif self._plot_type == 'timetrace': self._update_plot(ana, ishot)#, color_order) elif self._plot_type == 'stepplot': self._update_plot(ana, ishot)#, color_order) elif self._plot_type == 'contour': self._update_contour(ana, ishot) elif self._plot_type == 'image': self._update_image(ana, ishot) elif self._plot_type == 'surface': self._update_surface(ana, ishot) elif self._plot_type == 'axspan': self._update_axspan(ana, ishot) elif self._plot_type == 'axline': self._update_axline(ana, ishot) elif self._plot_type == 'text': self._update_text(ana, ishot) obj = self.get_child(idx=ishot) if obj.is_suppress(): return False obj._data_extent = None try: if (self.get_figaxes() is not None): self.get_figaxes().adjust_axes_range() except: dprint1("failed in adjusting axes at postprocess_data, continuing...") pass return True
def onScope1D(self, evt): from ifigure.mto.fig_plot import FigPlot y = self._content().nc_eval(self._td) obj = FigPlot(y) self._on_scope(obj, False)
def args2var(self): val = FigPlot.args2var(self) if self.getvar('enabled_point') == 'all': self.setp('enabled_point', [True]*(self.getp('x').size)) return val
def attr_in_file(self): return ['enabled_point'] + FigPlot.attr_in_file()
def __init__(self, *args, **kargs): FigPlot.__init__(self, *args, **kargs) FigControl.__init__(self) self._figc_hit = -1 self._enable_a = None self._mark_a = None
def __init__(self, *args, **kargs): kargs['style'] = (wx.FRAME_FLOAT_ON_PARENT | wx.MINIMIZE_BOX | wx.MAXIMIZE_BOX | wx.RESIZE_BORDER | wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.CLIP_CHILDREN) # print kargs BookViewer.__init__(self, *args, **kargs) f_page = self.get_page(0) f_page.set_section(2) f_axes = self.get_axes(0, 0) for name, child in f_axes.get_children(): child.destroy() obj = FigPlot([0], [0]) f_axes.add_child('xslice_plot1', obj) obj.set_suppress(True) obj = FigPlot([0], [0]) f_axes.add_child('xslice_plot2', obj) obj.set_suppress(True) f_axes.realize() f_axes = self.get_axes(0, 1) for name, child in f_axes.get_children(): child.destroy() obj = FigPlot([0], [0]) f_axes.add_child('xslice_plot1', obj) obj.set_suppress(True) obj = FigPlot([0], [0]) f_axes.add_child('xslice_plot2', obj) obj.set_suppress(True) f_axes.realize()