当前位置: 首页>>代码示例>>Python>>正文


Python AxesWidget.connect_event方法代码示例

本文整理汇总了Python中matplotlib.widgets.AxesWidget.connect_event方法的典型用法代码示例。如果您正苦于以下问题:Python AxesWidget.connect_event方法的具体用法?Python AxesWidget.connect_event怎么用?Python AxesWidget.connect_event使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在matplotlib.widgets.AxesWidget的用法示例。


在下文中一共展示了AxesWidget.connect_event方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: PlotPlotPanel

# 需要导入模块: from matplotlib.widgets import AxesWidget [as 别名]
# 或者: from matplotlib.widgets.AxesWidget import connect_event [as 别名]
class PlotPlotPanel(wx.Panel):
    def __init__(self, parent, dpi=None, **kwargs):
        wx.Panel.__init__(self, parent, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, **kwargs)
        self.ztv_frame = self.GetTopLevelParent()
        self.figure = Figure(dpi=None, figsize=(1.,1.))
        self.axes = self.figure.add_subplot(111)
        self.canvas = FigureCanvasWxAgg(self, -1, self.figure)
        self.Bind(wx.EVT_SIZE, self._onSize)
        self.axes_widget = AxesWidget(self.figure.gca())
        self.axes_widget.connect_event('motion_notify_event', self.on_motion)
        self.plot_point = None
        
    def on_motion(self, evt):
        if evt.xdata is not None:
            xarg = np.abs(self.ztv_frame.plot_panel.plot_positions - evt.xdata).argmin()
            ydata = self.ztv_frame.plot_panel.plot_im_values[xarg]
            self.ztv_frame.plot_panel.cursor_position_textctrl.SetValue('{0:.6g},{1:.6g}'.format(evt.xdata, ydata))
            if self.plot_point is None:
                self.plot_point, = self.axes.plot([evt.xdata], [ydata], 'xm')
            else:
                self.plot_point.set_data([[evt.xdata], [ydata]])
            self.figure.canvas.draw()

    def _onSize(self, event):
        self._SetSize()

    def _SetSize(self):
        pixels = tuple(self.GetClientSize())
        self.SetSize(pixels)
        self.canvas.SetSize(pixels)
        self.figure.set_size_inches(float(pixels[0])/self.figure.get_dpi(), float(pixels[1])/self.figure.get_dpi())
开发者ID:henryroe,项目名称:ztv,代码行数:33,代码来源:plot_panel.py

示例2: PhotPlotPanel

# 需要导入模块: from matplotlib.widgets import AxesWidget [as 别名]
# 或者: from matplotlib.widgets.AxesWidget import connect_event [as 别名]
class PhotPlotPanel(wx.Panel):
    def __init__(self, parent, dpi=None, **kwargs):
        wx.Panel.__init__(self, parent, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, **kwargs)
        self.ztv_frame = self.GetTopLevelParent()
        self.figure = Figure(dpi=None, figsize=(1.,1.))
        self.axes = self.figure.add_subplot(111)
        self.canvas = FigureCanvasWxAgg(self, -1, self.figure)
        self.Bind(wx.EVT_SIZE, self._onSize)
        self.axes_widget = AxesWidget(self.figure.gca())
        self.axes_widget.connect_event('motion_notify_event', self.on_motion)
        self.axes_widget.connect_event('button_press_event', self.on_button_press)
        self.axes_widget.connect_event('button_release_event', self.on_button_release)
        self.axes_widget.connect_event('figure_leave_event', self.on_cursor_leave)
        self.button_down = False

    def on_button_press(self, event):
        self.aper_names = ['aprad', 'skyradin', 'skyradout']
        self.aper_last_radii = np.array([self.ztv_frame.phot_panel.aprad, 
                                         self.ztv_frame.phot_panel.skyradin,
                                         self.ztv_frame.phot_panel.skyradout])
        self.button_press_xdata = event.xdata
        self.cur_aper_index = np.abs(self.aper_last_radii - event.xdata).argmin()
        self.cur_aper_name = self.aper_names[self.cur_aper_index]
        # but, click must be within +-N pix to be valid
        if np.abs(event.xdata - self.aper_last_radii[self.cur_aper_index]) <= 20:
            self.button_down = True

    def on_motion(self, event):
        if self.button_down:
            if event.xdata is not None:
                if self.cur_aper_name == 'aprad':
                    self.ztv_frame.phot_panel.aprad = (self.aper_last_radii[self.cur_aper_index] +
                                                       (event.xdata - self.button_press_xdata))
                    self.ztv_frame.phot_panel.aprad_textctrl.SetValue('{0:.2f}'.format(self.ztv_frame.phot_panel.aprad))
                    set_textctrl_background_color(self.ztv_frame.phot_panel.aprad_textctrl, 'ok')
                elif self.cur_aper_name == 'skyradin':
                    self.ztv_frame.phot_panel.skyradin = (self.aper_last_radii[self.cur_aper_index] +
                                                          (event.xdata - self.button_press_xdata))
                    self.ztv_frame.phot_panel.skyradin_textctrl.SetValue('{0:.2f}'.format( 
                                                                       self.ztv_frame.phot_panel.skyradin))
                    set_textctrl_background_color(self.ztv_frame.phot_panel.skyradin_textctrl, 'ok')
                elif self.cur_aper_name == 'skyradout':
                    self.ztv_frame.phot_panel.skyradout = (self.aper_last_radii[self.cur_aper_index] +
                                                           (event.xdata - self.button_press_xdata))
                    self.ztv_frame.phot_panel.skyradout_textctrl.SetValue('{0:.2f}'.format( 
                                                                       self.ztv_frame.phot_panel.skyradout))
                    set_textctrl_background_color(self.ztv_frame.phot_panel.skyradout_textctrl, 'ok')
                self.ztv_frame.phot_panel.recalc_phot()

    def on_button_release(self, event):
        if self.button_down:
            if event.xdata is not None:
                if self.cur_aper_name == 'aprad':
                    self.ztv_frame.phot_panel.aprad = (self.aper_last_radii[self.cur_aper_index] +
                                                       (event.xdata - self.button_press_xdata))
                    self.ztv_frame.phot_panel.aprad_textctrl.SetValue('{0:.2f}'.format(self.ztv_frame.phot_panel.aprad))
                    set_textctrl_background_color(self.ztv_frame.phot_panel.aprad_textctrl, 'ok')
                elif self.cur_aper_name == 'skyradin':
                    self.ztv_frame.phot_panel.skyradin = (self.aper_last_radii[self.cur_aper_index] +
                                                          (event.xdata - self.button_press_xdata))
                    self.ztv_frame.phot_panel.skyradin_textctrl.SetValue('{0:.2f}'.format( 
                                                                       self.ztv_frame.phot_panel.skyradin))
                    set_textctrl_background_color(self.ztv_frame.phot_panel.skyradin_textctrl, 'ok')
                elif self.cur_aper_name == 'skyradout':
                    self.ztv_frame.phot_panel.skyradout = (self.aper_last_radii[self.cur_aper_index] +
                                                           (event.xdata - self.button_press_xdata))
                    self.ztv_frame.phot_panel.skyradout_textctrl.SetValue('{0:.2f}'.format( 
                                                                       self.ztv_frame.phot_panel.skyradout))
                    set_textctrl_background_color(self.ztv_frame.phot_panel.skyradout_textctrl, 'ok')
                self.ztv_frame.phot_panel.recalc_phot()
        self.button_down = False
    
    def on_cursor_leave(self, event):
        if self.button_down:
            if self.cur_aper_name == 'aprad':
                self.ztv_frame.phot_panel.aprad = self.aper_last_radii[self.cur_aper_index]
                self.ztv_frame.phot_panel.aprad_textctrl.SetValue('{0:.2f}'.format(self.ztv_frame.phot_panel.aprad))
                set_textctrl_background_color(self.ztv_frame.phot_panel.aprad_textctrl, 'ok')
            elif self.cur_aper_name == 'skyradin':
                self.ztv_frame.phot_panel.skyradin = self.aper_last_radii[self.cur_aper_index]
                self.ztv_frame.phot_panel.skyradin_textctrl.SetValue('{0:.2f}'.format( 
                                                                   self.ztv_frame.phot_panel.skyradin))
                set_textctrl_background_color(self.ztv_frame.phot_panel.skyradin_textctrl, 'ok')
            elif self.cur_aper_name == 'skyradout':
                self.ztv_frame.phot_panel.skyradout = self.aper_last_radii[self.cur_aper_index]
                self.ztv_frame.phot_panel.skyradout_textctrl.SetValue('{0:.2f}'.format( 
                                                                   self.ztv_frame.phot_panel.skyradout))
                set_textctrl_background_color(self.ztv_frame.phot_panel.skyradout_textctrl, 'ok')
            self.ztv_frame.phot_panel.recalc_phot()
        self.button_down=False

    def _onSize(self, event):
        self._SetSize()

    def _SetSize(self):
        pixels = tuple(self.GetClientSize())
        self.SetSize(pixels)
        self.canvas.SetSize(pixels)
        self.figure.set_size_inches(float(pixels[0])/self.figure.get_dpi(), float(pixels[1])/self.figure.get_dpi())
开发者ID:henryroe,项目名称:ztv,代码行数:101,代码来源:phot_panel.py

示例3: AtmosViewer

# 需要导入模块: from matplotlib.widgets import AxesWidget [as 别名]
# 或者: from matplotlib.widgets.AxesWidget import connect_event [as 别名]

#.........这里部分代码省略.........
            self.axes.lines.pop(self.axes.lines.index(self.selected_line))
        if self.selected_line_text in self.axes.texts:
            self.axes.texts.remove(self.selected_line_text)
        self.selected_line = None
        self.selected_line_text = None
        self.selected_line_wavenumber = -1
        if len(self.molecule_lookup_points) == 0:
            return
        closest = {'name':None, 'wn':-1., 'dist':9e9}
        for cur_molecule in self.molecule_lookup_points:
            wn = self.molecule_lookup_points[cur_molecule]['wn']
            ys = self.molecule_lookup_points[cur_molecule]['y']
            dist_x2 = (wn - event.xdata)**2
            xlim = self.axes.get_xlim()
            scale = ((xlim[1] - xlim[0]) /  # this is like wavenumbers/inch
                     (self.axes.figure.get_figwidth() * self.axes.get_position().bounds[2]))
            dist_y2 = ((ys - event.ydata)*(self.axes.figure.get_figheight() *
                                                  self.axes.get_position().bounds[3]) * scale)**2
            dist = np.sqrt(dist_x2 + dist_y2)
            if dist.min() < closest['dist']:
                closest = {'name':cur_molecule, 'wn':wn[dist.argmin()], 'dist':dist.min()}
        self.selected_line_wavenumber = closest['wn']
        self.selected_line = self.axes.plot([closest['wn'], closest['wn']], [0, 1], '-.', color='black')[0]
        self.selected_line_text = self.axes.annotate(closest['name'] + ('%11.5f' % closest['wn']),
                                                     (closest['wn'], 1.03), ha='center',
                                                     annotation_clip=False)
        self.redraw()

    def on_scroll(self, event):
        self.central_wavenumber += self.bandwidth * event.step

    def _all_on_fired(self):
        self.selected_molecules = self.molecules.keys()

    def _all_off_fired(self):
        self.selected_molecules = []

    def mpl_setup(self):
        self.axes_widget = AxesWidget(self.figure.gca())
        self.axes_widget.connect_event('button_press_event', self.on_click)
        self.axes_widget.connect_event('scroll_event', self.on_scroll)

    @on_trait_change("central_wavenumber, bandwidth")
    def replot_molecular_overplots(self):
        for i, cur_molecule in enumerate(self.selected_molecules):
            if self.molecules[cur_molecule]['hitran'] is None:
                self.molecules[cur_molecule]['hitran'] = pandas.io.parsers.read_csv( gzip.open(
                                        self.molecules[cur_molecule]['hitran_filename'], 'r'), skiprows=2)
            wn = self.molecules[cur_molecule]['hitran']['wavenumber']
            intensity = self.molecules[cur_molecule]['hitran']['intensity']
            w = ( (wn >= self.central_wavenumber - self.bandwidth / 2.) &
                  (wn <= self.central_wavenumber + self.bandwidth / 2.) )
            wn = wn[w]
            intensity = intensity[w]
            plot_orders_of_magnitude = 2.
            max_line_intensity = intensity.max()
            min_line_intensity = max_line_intensity / 10**plot_orders_of_magnitude
            wn = wn[intensity >= min_line_intensity]
            intensity = intensity[intensity >= min_line_intensity]
            intensity = ((np.log10(intensity) - np.log10(min_line_intensity)) /
                         (np.log10(max_line_intensity) - np.log10(min_line_intensity)))
            intensity = intensity * 0.1
            self.molecule_lookup_points[cur_molecule] = {'wn':wn, 'y':intensity + (i * 0.1) + 0.05}
            wn = wn.repeat(3)
            intensity = np.column_stack((np.zeros(len(intensity)),
                                         intensity,
                                         np.zeros(len(intensity)))).flatten() + (i * 0.1) + 0.05
            newplot = self.axes.plot(wn, intensity, self.molecules[cur_molecule]['color'])
            newtext = self.axes.annotate(cur_molecule, (self.central_wavenumber + self.bandwidth * 0.51,
                                                        i * 0.1 + 0.065), ha='left',
                                         va='center', annotation_clip=False, color=self.molecules[cur_molecule]['color'])
            if self.molecules[cur_molecule]['plot_lines'] in self.axes.lines:
                self.axes.lines.pop(self.axes.lines.index(self.molecules[cur_molecule]['plot_lines']))
            self.molecules[cur_molecule]['plot_lines'] = None
            if self.molecules[cur_molecule]['plot_text'] in self.axes.texts:
                self.axes.texts.remove(self.molecules[cur_molecule]['plot_text'])
                self.molecules[cur_molecule]['plot_text'] = None
            self.molecules[cur_molecule]['plot_lines'] = newplot[0]
            self.molecules[cur_molecule]['plot_text'] = newtext
        self.redraw()

    def _selected_molecules_changed(self, old, new):
        self.replot_molecular_overplots()
        for cur_molecule in old:
            if cur_molecule not in new:
                if self.molecules[cur_molecule]['plot_lines'] in self.axes.lines:
                    self.axes.lines.pop(self.axes.lines.index(self.molecules[cur_molecule]['plot_lines']))
                if self.molecules[cur_molecule]['plot_text'] in self.axes.texts:
                    self.axes.texts.remove(self.molecules[cur_molecule]['plot_text'])
                self.molecules[cur_molecule]['plot_lines'] = None
                self.molecules[cur_molecule]['plot_text'] = None
                self.molecule_lookup_points.pop(cur_molecule, None)
        self.redraw()

    @on_trait_change("central_wavenumber, bandwidth")
    def redraw(self):
        self.axes.set_xlim(self.central_wavenumber - self.bandwidth / 2.,
                           self.central_wavenumber + self.bandwidth / 2.)
        self.axes.set_ylim(0, 1.0)
        self.figure.canvas.draw()
开发者ID:henryroe,项目名称:xatmos,代码行数:104,代码来源:xatmos.py


注:本文中的matplotlib.widgets.AxesWidget.connect_event方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。