python类figure()的实例源码

phot_panel.py 文件源码 项目:CAAPR 作者: Stargrazer82301 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def redraw_overplot_on_image(self, *args):
        if self.star_center_patch is not None:
            self.ztv_frame.primary_image_panel.axes.patches.remove(self.star_center_patch)
        if self.star_aperture_patch is not None:
            self.ztv_frame.primary_image_panel.axes.patches.remove(self.star_aperture_patch)
        if self.sky_aperture_patch is not None:
            self.ztv_frame.primary_image_panel.axes.patches.remove(self.sky_aperture_patch)
        self.star_center_patch = Circle([self.xcentroid, self.ycentroid], 0.125, color=self.aprad_color)
        self.ztv_frame.primary_image_panel.axes.add_patch(self.star_center_patch)
        self.star_aperture_patch = Circle([self.xcentroid, self.ycentroid], self.aprad, color=self.aprad_color, alpha=self.alpha)
        self.ztv_frame.primary_image_panel.axes.add_patch(self.star_aperture_patch)
        self.sky_aperture_patch = Wedge([self.xcentroid, self.ycentroid], self.skyradout, 0., 360., 
                                        width=self.skyradout - self.skyradin, color=self.skyrad_color, alpha=self.alpha)
        self.ztv_frame.primary_image_panel.axes.add_patch(self.sky_aperture_patch)
        self.ztv_frame.primary_image_panel.figure.canvas.draw()
        self.hideshow_button.SetLabel(u"Hide")
test_pylabtools.py 文件源码 项目:leetcode 作者: thomasyimgit 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def test_select_figure_formats_kwargs():
    ip = get_ipython()
    kwargs = dict(quality=10, bbox_inches='tight')
    pt.select_figure_formats(ip, 'png', **kwargs)
    formatter = ip.display_formatter.formatters['image/png']
    f = formatter.lookup_by_type(Figure)
    cell = f.__closure__[0].cell_contents
    nt.assert_equal(cell, kwargs)

    # check that the formatter doesn't raise
    fig = plt.figure()
    ax = fig.add_subplot(1,1,1)
    ax.plot([1,2,3])
    plt.draw()
    formatter.enabled = True
    png = formatter(fig)
    assert png.startswith(_PNG)
pylabtools.py 文件源码 项目:leetcode 作者: thomasyimgit 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def getfigs(*fig_nums):
    """Get a list of matplotlib figures by figure numbers.

    If no arguments are given, all available figures are returned.  If the
    argument list contains references to invalid figures, a warning is printed
    but the function continues pasting further figures.

    Parameters
    ----------
    figs : tuple
        A tuple of ints giving the figure numbers of the figures to return.
    """
    from matplotlib._pylab_helpers import Gcf
    if not fig_nums:
        fig_managers = Gcf.get_all_fig_managers()
        return [fm.canvas.figure for fm in fig_managers]
    else:
        figs = []
        for num in fig_nums:
            f = Gcf.figs.get(num)
            if f is None:
                print('Warning: figure %s not available.' % num)
            else:
                figs.append(f.canvas.figure)
        return figs
matplotlib_renderer.py 文件源码 项目:MDT 作者: cbclab 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def __init__(self, figure, plotting_info_viewer, controller):
        self.figure = figure
        self.plotting_info_viewer = plotting_info_viewer
        self.controller = controller

        self._axes_data = []
        self.figure.canvas.mpl_connect('button_press_event', self._button_pressed)
        self.figure.canvas.mpl_connect('button_release_event', self._button_released)
        self.figure.canvas.mpl_connect('motion_notify_event', self._mouse_motion)
        self.figure.canvas.mpl_connect('scroll_event', self._scroll_event)
        self.figure.canvas.mpl_connect('key_press_event', self._on_key_press)
        self.figure.canvas.mpl_connect('key_release_event', self._on_key_release)

        self._in_drag = False
        self._control_is_held = False

        self._scrolling_manager = _ScrollingManager(controller)
        self._dragging_manager = _DraggingManager(controller)
gui.py 文件源码 项目:skan 作者: jni 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def make_figure_window(self):
        self.figure_window = tk.Toplevel(self)
        self.figure_window.wm_title('Preview')
        screen_dpi = self.figure_window.winfo_fpixels('1i')
        screen_width = self.figure_window.winfo_screenwidth()  # in pixels
        figure_width = screen_width / 2 / screen_dpi
        figure_height = 0.75 * figure_width
        self.figure = Figure(figsize=(figure_width, figure_height),
                             dpi=screen_dpi)
        ax0 = self.figure.add_subplot(221)
        axes = [self.figure.add_subplot(220 + i, sharex=ax0, sharey=ax0)
                for i in range(2, 5)]
        self.axes = np.array([ax0] + axes)
        canvas = FigureCanvasTkAgg(self.figure, master=self.figure_window)
        canvas.show()
        canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=1)
        toolbar = NavigationToolbar2TkAgg(canvas, self.figure_window)
        toolbar.update()
        canvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=1)
base_plot_types.py 文件源码 项目:yt 作者: yt-project 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __init__(self, viewer, window_plot, frb, field, font_properties,
                 font_color):
        self.frb = frb
        self.data = frb.data_source
        self._axes = window_plot.axes
        self._figure = window_plot.figure
        if len(self._axes.images) > 0:
            self.image = self._axes.images[0]
        if frb.axis < 3:
            DD = frb.ds.domain_width
            xax = frb.ds.coordinates.x_axis[frb.axis]
            yax = frb.ds.coordinates.y_axis[frb.axis]
            self._period = (DD[xax], DD[yax])
        self.ds = frb.ds
        self.xlim = viewer.xlim
        self.ylim = viewer.ylim
        if 'OffAxisSlice' in viewer._plot_type:
            self._type_name = "CuttingPlane"
        else:
            self._type_name = viewer._plot_type
        self.aspect = window_plot._aspect
        self.font_properties = font_properties
        self.font_color = font_color
        self.field = field
old_camera.py 文件源码 项目:yt 作者: yt-project 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def show_mpl(self, im, enhance=True, clear_fig=True):
        if self._pylab is None:
            import pylab
            self._pylab = pylab
        if self._render_figure is None:
            self._render_figure = self._pylab.figure(1)
        if clear_fig: self._render_figure.clf()

        if enhance:
            nz = im[im > 0.0]
            nim = im / (nz.mean() + 6.0 * np.std(nz))
            nim[nim > 1.0] = 1.0
            nim[nim < 0.0] = 0.0
            del nz
        else:
            nim = im
        ax = self._pylab.imshow(nim[:,:,:3]/nim[:,:,:3].max(), origin='upper')
        return ax
old_camera.py 文件源码 项目:yt 作者: yt-project 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def plot_allsky_healpix(image, nside, fn, label = "", rotation = None,
                        take_log = True, resolution=512, cmin=None, cmax=None):
    import matplotlib.figure
    import matplotlib.backends.backend_agg
    if rotation is None: rotation = np.eye(3).astype("float64")

    img, count = pixelize_healpix(nside, image, resolution, resolution, rotation)

    fig = matplotlib.figure.Figure((10, 5))
    ax = fig.add_subplot(1,1,1,projection='aitoff')
    if take_log: func = np.log10
    else: func = lambda a: a
    implot = ax.imshow(func(img), extent=(-np.pi,np.pi,-np.pi/2,np.pi/2),
                       clip_on=False, aspect=0.5, vmin=cmin, vmax=cmax)
    cb = fig.colorbar(implot, orientation='horizontal')
    cb.set_label(label)
    ax.xaxis.set_ticks(())
    ax.yaxis.set_ticks(())
    canvas = matplotlib.backends.backend_agg.FigureCanvasAgg(fig)
    canvas.print_figure(fn)
    return img, count
Pairwise_offset_algorithm.py 文件源码 项目:dxf2gcode 作者: cnc-club 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def __init__(self, master = []):

        self.master = master

        # Erstellen des Fensters mit Rahmen und Canvas
        self.figure = Figure(figsize = (7, 7), dpi = 100)
        self.frame_c = Frame(relief = GROOVE, bd = 2)
        self.frame_c.pack(fill = BOTH, expand = 1,)
        self.canvas = FigureCanvasTkAgg(self.figure, master = self.frame_c)
        self.canvas.show()
        self.canvas.get_tk_widget().pack(fill = BOTH, expand = 1)

        # Erstellen der Toolbar unten
        self.toolbar = NavigationToolbar2TkAgg(self.canvas, self.frame_c)
        self.toolbar.update()
        self.canvas._tkcanvas.pack(fill = BOTH, expand = 1)
Pairwise_offset_algorithm.py 文件源码 项目:dxf2gcode 作者: cnc-club 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def plot_lines_plot(self, lines, sb_nr = 111, text = "", wtp = [True, True, True]):
        self.plot1 = self.figure.add_subplot(sb_nr)
        self.plot1.set_title("Lines Plot %s" % sb_nr)
        self.plot1.grid(b = True, which = 'both', color = '0.65', linestyle = '-')
        self.plot1.hold(True)
        self.plot1.text(0.5, 0, text, ha = 'left', fontsize = 8)

        for line_nr in range(len(lines)):

            line = lines[line_nr]
            if wtp[0]:
                line.plot2plot(self.plot1)
            if wtp[1]:
                line.Ps.plot2plot(self.plot1, format = 'xr')
                line.Pe.plot2plot(self.plot1, format = 'og')
            Ps = (line.Ps + line.Pe) * 0.5
            if wtp[2]:
                self.plot1.text(Ps.x, Ps.y, line_nr, ha = 'left', fontsize = 10, color = 'red')

        self.plot1.axis('scaled')
        self.plot1.margins(y = .1, x = .1)
        self.plot1.autoscale(True, 'both', False)
        self.canvas.show()
travelling_salesman_problem_2.py 文件源码 项目:dxf2gcode 作者: cnc-club 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def ini_plot(self):
        self.plot1 = self.figure.add_subplot(211)
        self.plot1.set_title("Number of Lines: " +str(self.iter.Lines.num))

        self.plot2 = self.figure.add_subplot(212)
        self.plot2.set_title(('Best Tour length: %0.1f ' % (self.iter.Fittness.best_fittness[-1])))
        self.plot2.set_xlabel('Iteration')
        self.plot2.set_ylabel('Tour Length')        

        nr = 0
        self.plot1.hold(True)
        for line in self.iter.Lines.lines:
            line.plot_line(self.plot1,'-ro')
            line.add_text(self.plot1, str(nr))
            nr += 1

        self.lines1 = []
        con_lines = self.gen_plot_route()
        for line in con_lines:
            line.plot_line(self.plot1,'-b')

        best_fittness = self.iter.Fittness.best_fittness
        self.line2 = self.plot2.plot(range(len(best_fittness)), best_fittness, 'r-')
        self.plot2.set_ylim(0, best_fittness[0]+5)
        self.canvas.show()
Ellipse_fitting_by_Biarc_curves.py 文件源码 项目:dxf2gcode 作者: cnc-club 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def __init__(self,master=[]):

        self.master=master

        #Erstellen des Fensters mit Rahmen und Canvas
        self.figure = Figure(figsize=(7,7), dpi=100)
        self.frame_c=Frame(relief = GROOVE,bd = 2)
        self.frame_c.pack(fill=BOTH, expand=1,)
        self.canvas = FigureCanvasTkAgg(self.figure, master=self.frame_c)
        self.canvas.show()
        self.canvas.get_tk_widget().pack(fill=BOTH, expand=1)

        #Erstellen der Toolbar unten
        self.toolbar = NavigationToolbar2TkAgg(self.canvas, self.frame_c)
        self.toolbar.update()
        self.canvas._tkcanvas.pack( fill=BOTH, expand=1)
Ellipse_fitting_by_Biarc_curves.py 文件源码 项目:dxf2gcode 作者: cnc-club 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def make_ellipse_biarc_plot(self,ellipse):
        self.plot1 = self.figure.add_subplot(111)
        self.plot1.set_title("Ellipse, BIARC Fitting Algorithms: ")

        arrow_len=4
        arrow_width=arrow_len*0.05


        self.plot1.hold(True)
        for PtsVec in ellipse.PtsVec:
            (PtsVec[0].x)
            (PtsVec[0].y)
            self.plot1.plot([PtsVec[0].x],[PtsVec[0].y],'xr')

            self.plot1.arrow(PtsVec[0].x,PtsVec[0].y,\
                             cos(PtsVec[1])*arrow_len,\
                             sin(PtsVec[1])*arrow_len,\
                             width=arrow_width)        

        for geo in ellipse.geo:
            geo.plot2plot(self.plot1)
        self.plot1.axis('scaled')     
        self.canvas.show()
NURBS_fitting_by_Biarc_curves_wx.py 文件源码 项目:dxf2gcode 作者: cnc-club 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__(self):
        wx.Frame.__init__(self,None,-1,
                         'CanvasFrame',size=(550,350))



        self.SetBackgroundColour(wx.NamedColor("WHITE"))

        self.figure = Figure()
        self.axes = self.figure.add_subplot(111)

        self.canvas = FigureCanvas(self, -1, self.figure)

        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
        self.SetSizer(self.sizer)
        self.Fit()

        self.add_toolbar()  # comment this out for no toolbar

        self.axes.set_title("NURBS and B-Spline Algorithms: ")
NURBS_fitting_by_Biarc_curves_wx.py 文件源码 项目:dxf2gcode 作者: cnc-club 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def add_toolbar(self):
        self.toolbar = NavigationToolbar2Wx(self.canvas)
        self.toolbar.Realize()
        if wx.Platform == '__WXMAC__':
            # Mac platform (OSX 10.3, MacPython) does not seem to cope with
            # having a toolbar in a sizer. This work-around gets the buttons
            # back, but at the expense of having the toolbar at the top
            self.SetToolBar(self.toolbar)
        else:
            # On Windows platform, default window size is incorrect, so set
            # toolbar width to figure width.
            tw, th = self.toolbar.GetSizeTuple()
            fw, fh = self.canvas.GetSizeTuple()
            # By adding toolbar in sizer, we are able to put it at the bottom
            # of the frame - so appearance is closer to GTK version.
            # As noted above, doesn't work for Mac.
            self.toolbar.SetSize(wx.Size(fw, th))
            self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
        # update the axes menu on the toolbar
        self.toolbar.update()
plot_panel.py 文件源码 项目:CAAPR 作者: Stargrazer82301 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def redraw_overplot_on_image(self, msg=None):
        if self.primary_image_patch is not None:
            self.ztv_frame.primary_image_panel.axes.patches.remove(self.primary_image_patch)
        if self.start_pt == self.end_pt:
            path = Path([self.start_pt, self.start_pt + (0.5, 0.),
                         self.start_pt, self.start_pt + (-0.5, 0.), 
                         self.start_pt, self.start_pt + (0., 0.5), 
                         self.start_pt, self.start_pt + (0., -0.5), self.start_pt], 
                        [Path.MOVETO, Path.LINETO, Path.LINETO, Path.LINETO, Path.LINETO, 
                         Path.LINETO, Path.LINETO, Path.LINETO, Path.LINETO])
        else:
            path = Path([self.start_pt, self.end_pt], [Path.MOVETO, Path.LINETO])
        self.primary_image_patch = PathPatch(path, color='magenta', lw=1)
        self.ztv_frame.primary_image_panel.axes.add_patch(self.primary_image_patch)
        self.ztv_frame.primary_image_panel.figure.canvas.draw()
        self.hideshow_button.SetLabel(u"Hide")
ztv.py 文件源码 项目:CAAPR 作者: Stargrazer82301 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def set_and_get_xy_limits(self):
        canvas_size = self.canvas.GetSize()
        num_x_pixels = canvas_size.x
        halfsize = (num_x_pixels / 2.0) / self.ztv_frame.zoom_factor
        xlim = (self.center.x - halfsize, self.center.x + halfsize)
        self.axes.set_xlim(xlim)
        num_y_pixels = canvas_size.y
        halfsize = (num_y_pixels / 2.0) / self.ztv_frame.zoom_factor
        ylim = (self.center.y - halfsize, self.center.y + halfsize)
        self.axes.set_ylim(ylim)
        self.figure.canvas.draw()  # bulk of time in method is spent in this line: TODO: look for ways to make faster
        send_change_message = True
        if xlim == self.xlim and ylim == self.ylim:
            send_change_message = False
        self.xlim, self.ylim = xlim, ylim
        if send_change_message:
            wx.CallAfter(pub.sendMessage, 'primary-xy-limits-changed', msg=None)
        return {'xlim':xlim, 'ylim':ylim}
ztv.py 文件源码 项目:CAAPR 作者: Stargrazer82301 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def on_button_press(self, event):
        if event.button == 1:  # left button
            if self.cursor_mode == 'Zoom':
                if event.dblclick:
                    self.center = wx.RealPoint(event.xdata, event.ydata)
                    self.ztv_frame.zoom_factor /= 2.
                    self.set_and_get_xy_limits()
                else:
                    self.zoom_start_timestamp = time.time()
                    self.zoom_rect = Rectangle((event.xdata, event.ydata), 0, 0,
                                               color='orange', fill=False, zorder=100)
                    self.axes.add_patch(self.zoom_rect)
                    self.figure.canvas.draw()
            elif self.cursor_mode == 'Pan':
                self.center = wx.RealPoint(event.xdata, event.ydata)
                self.set_and_get_xy_limits()
            else:
                if (self.available_cursor_modes.has_key(self.cursor_mode) and
                    self.available_cursor_modes[self.cursor_mode].has_key('on_button_press')):
                    self.available_cursor_modes[self.cursor_mode]['on_button_press'](event)
ztv.py 文件源码 项目:CAAPR 作者: Stargrazer82301 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def __init__(self, parent, size=wx.Size(128,128), dpi=None, **kwargs):
        self.size = size
        self.dragging_curview_is_active = False
        wx.Panel.__init__(self, parent, wx.ID_ANY, wx.DefaultPosition, size, 0, **kwargs)
        self.ztv_frame = self.GetTopLevelParent()
        self.figure = Figure(None, dpi)
        self.axes = self.figure.add_axes([0., 0., 1., 1.])
        self.curview_rectangle = Rectangle((0, 0), 1, 1, color='orange', fill=False, zorder=100)
        self.axes.add_patch(self.curview_rectangle)
        self.canvas = FigureCanvasWxAgg(self, -1, self.figure)
        self.overview_zoom_factor = 1.
        self._SetSize()
        self.set_xy_limits()
        self.axes_widget = AxesWidget(self.figure.gca())
        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('motion_notify_event', self.on_motion)
        pub.subscribe(self.redraw_overview_image, 'redraw-image')   
        pub.subscribe(self.redraw_box, 'primary-xy-limits-changed')
ztv.py 文件源码 项目:CAAPR 作者: Stargrazer82301 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def redraw_overview_image(self, msg=None):
        if msg is True or self.ztv_frame._pause_redraw_image:
            return
        if hasattr(self, 'axes_image'):
            if self.axes_image in self.axes.images:
                self.axes.images.remove(self.axes_image)
        # note that following is not an actual rebin, but a sub-sampling, which is what matplotlib ultimately
        # would do on its own anyway if we gave it the full image.  But, matplotlib takes longer.  For a 2Kx2K
        # image, this saves almost 0.3sec on a ~2014 MacBookProRetina
        max_rebin_x = float(self.ztv_frame.display_image.shape[1]) / self.size.x
        max_rebin_y = float(self.ztv_frame.display_image.shape[0]) / self.size.y
        rebin_factor = max(1, np.int(np.floor(min([max_rebin_x, max_rebin_y]))))
        self.axes_image = self.axes.imshow(self.ztv_frame.normalize(self.ztv_frame.display_image)[::rebin_factor, 
                                                                                                  ::rebin_factor],
                                           interpolation='Nearest', vmin=0., vmax=1.,
                                           extent=[0., self.ztv_frame.display_image.shape[1], 
                                                   self.ztv_frame.display_image.shape[0], 0.],
                                           cmap=self.ztv_frame.get_cmap_to_display(), zorder=0)
        clear_ticks_and_frame_from_axes(self.axes)
        self.set_xy_limits()
        self.figure.canvas.draw()
plot_panel.py 文件源码 项目:CAAPR 作者: Stargrazer82301 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def redraw_overplot_on_image(self, msg=None):
        if self.primary_image_patch is not None:
            self.ztv_frame.primary_image_panel.axes.patches.remove(self.primary_image_patch)
        if self.start_pt == self.end_pt:
            path = Path([self.start_pt, self.start_pt + (0.5, 0.),
                         self.start_pt, self.start_pt + (-0.5, 0.), 
                         self.start_pt, self.start_pt + (0., 0.5), 
                         self.start_pt, self.start_pt + (0., -0.5), self.start_pt], 
                        [Path.MOVETO, Path.LINETO, Path.LINETO, Path.LINETO, Path.LINETO, 
                         Path.LINETO, Path.LINETO, Path.LINETO, Path.LINETO])
        else:
            path = Path([self.start_pt, self.end_pt], [Path.MOVETO, Path.LINETO])
        self.primary_image_patch = PathPatch(path, color='magenta', lw=1)
        self.ztv_frame.primary_image_panel.axes.add_patch(self.primary_image_patch)
        self.ztv_frame.primary_image_panel.figure.canvas.draw()
        self.hideshow_button.SetLabel(u"Hide")
ztv.py 文件源码 项目:CAAPR 作者: Stargrazer82301 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def on_button_press(self, event):
        if event.button == 1:  # left button
            if self.cursor_mode == 'Zoom':
                if event.dblclick:
                    self.center = wx.RealPoint(event.xdata, event.ydata)
                    self.ztv_frame.zoom_factor /= 2.
                    self.set_and_get_xy_limits()
                else:
                    self.zoom_start_timestamp = time.time()
                    self.zoom_rect = Rectangle((event.xdata, event.ydata), 0, 0,
                                               color='orange', fill=False, zorder=100)
                    self.axes.add_patch(self.zoom_rect)
                    self.figure.canvas.draw()
            elif self.cursor_mode == 'Pan':
                self.center = wx.RealPoint(event.xdata, event.ydata)
                self.set_and_get_xy_limits()
            else:
                if (self.available_cursor_modes.has_key(self.cursor_mode) and
                    self.available_cursor_modes[self.cursor_mode].has_key('on_button_press')):
                    self.available_cursor_modes[self.cursor_mode]['on_button_press'](event)
ztv.py 文件源码 项目:CAAPR 作者: Stargrazer82301 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def on_right_down(self, event):
        if self.popup_menu_needs_rebuild or self.popup_menu is None:
            self.init_popup_menu()
        for cursor_mode in self.cursor_mode_to_eventID:
            self.popup_menu.Check(self.cursor_mode_to_eventID[cursor_mode], False)
        self.popup_menu.Check(self.cursor_mode_to_eventID[self.cursor_mode], True)
        for cmap in self.ztv_frame.available_cmaps:
            self.popup_menu.Check(self.cmap_to_eventID[cmap], False)
        self.popup_menu.Check(self.cmap_to_eventID[self.ztv_frame.cmap], True)
        for scaling in self.ztv_frame.available_scalings:
            self.popup_menu.Check(self.scaling_to_eventID[scaling], False)
        self.popup_menu.Check(self.scaling_to_eventID[self.ztv_frame.scaling], True)
        if self.ztv_frame.cur_fits_hdulist is None:
            self.popup_menu.Enable(self.popup_menu_cur_fits_header_eventID, False)
        else:
            self.popup_menu.Enable(self.popup_menu_cur_fits_header_eventID, True)
        self.figure.canvas.PopupMenuXY(self.popup_menu, event.GetX() + 8,  event.GetY() + 8)
ztv.py 文件源码 项目:CAAPR 作者: Stargrazer82301 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def __init__(self, parent, size=wx.Size(128,128), dpi=None, **kwargs):
        self.size = size
        self.dragging_curview_is_active = False
        wx.Panel.__init__(self, parent, wx.ID_ANY, wx.DefaultPosition, size, 0, **kwargs)
        self.ztv_frame = self.GetTopLevelParent()
        self.figure = Figure(None, dpi)
        self.axes = self.figure.add_axes([0., 0., 1., 1.])
        self.curview_rectangle = Rectangle((0, 0), 1, 1, color='orange', fill=False, zorder=100)
        self.axes.add_patch(self.curview_rectangle)
        self.canvas = FigureCanvasWxAgg(self, -1, self.figure)
        self.overview_zoom_factor = 1.
        self._SetSize()
        self.set_xy_limits()
        self.axes_widget = AxesWidget(self.figure.gca())
        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('motion_notify_event', self.on_motion)
        pub.subscribe(self.redraw_overview_image, 'redraw-image')   
        pub.subscribe(self.redraw_box, 'primary-xy-limits-changed')
ztv.py 文件源码 项目:CAAPR 作者: Stargrazer82301 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def redraw_overview_image(self, msg=None):
        if msg is True or self.ztv_frame._pause_redraw_image:
            return
        if hasattr(self, 'axes_image'):
            if self.axes_image in self.axes.images:
                self.axes.images.remove(self.axes_image)
        # note that following is not an actual rebin, but a sub-sampling, which is what matplotlib ultimately
        # would do on its own anyway if we gave it the full image.  But, matplotlib takes longer.  For a 2Kx2K
        # image, this saves almost 0.3sec on a ~2014 MacBookProRetina
        max_rebin_x = float(self.ztv_frame.display_image.shape[1]) / self.size.x
        max_rebin_y = float(self.ztv_frame.display_image.shape[0]) / self.size.y
        rebin_factor = max(1, np.int(np.floor(min([max_rebin_x, max_rebin_y]))))
        self.axes_image = self.axes.imshow(self.ztv_frame.normalize(self.ztv_frame.display_image)[::rebin_factor, 
                                                                                                  ::rebin_factor],
                                           interpolation='Nearest', vmin=0., vmax=1.,
                                           extent=[0., self.ztv_frame.display_image.shape[1], 
                                                   self.ztv_frame.display_image.shape[0], 0.],
                                           cmap=self.ztv_frame.get_cmap_to_display(), zorder=0)
        clear_ticks_and_frame_from_axes(self.axes)
        self.set_xy_limits()
        self.figure.canvas.draw()
mpl.py 文件源码 项目:smhr 作者: andycasey 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def _interactive_zoom_press(self, event):
        """
        Right-mouse button pressed in axis.

        :param event:
            A matplotlib event.
        """

        if event.button != 3 or event.inaxes is None:
            return None

        self._interactive_zoom_initial_bounds = [event.xdata, event.ydata]
        self._interactive_zoom_axis_index = self.figure.axes.index(event.inaxes)

        # Create lines if needed
        if self._interactive_zoom_axis_index not in self._right_click_zoom_box:
            self._right_click_zoom_box[self._interactive_zoom_axis_index] \
                = event.inaxes.plot([np.nan], [np.nan], "k:")[0]

        # Create zoom box signal
        self._interactive_zoom_box_signal = (
            time.time(),
            self.mpl_connect("motion_notify_event", self._update_interactive_zoom)
        )
        return None
backend_tkagg.py 文件源码 项目:PaleoView 作者: GlobalEcologyLab 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def __init__(self, canvas, num, window):
        FigureManagerBase.__init__(self, canvas, num)
        self.window = window
        self.window.withdraw()
        self.set_window_title("Figure %d" % num)
        self.canvas = canvas
        self._num =  num
        _, _, w, h = canvas.figure.bbox.bounds
        w, h = int(w), int(h)
        self.window.minsize(int(w*3/4),int(h*3/4))
        if matplotlib.rcParams['toolbar']=='classic':
            self.toolbar = NavigationToolbar( canvas, self.window )
        elif matplotlib.rcParams['toolbar']=='toolbar2':
            self.toolbar = NavigationToolbar2TkAgg( canvas, self.window )
        else:
            self.toolbar = None
        if self.toolbar is not None:
            self.toolbar.update()
        self.canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
        self._shown = False

        def notify_axes_change(fig):
            'this will be called whenever the current axes is changed'
            if self.toolbar != None: self.toolbar.update()
        self.canvas.figure.add_axobserver(notify_axes_change)
backend_tkagg.py 文件源码 项目:PaleoView 作者: GlobalEcologyLab 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def save_figure(self, *args):
        fs = FileDialog.SaveFileDialog(master=self.window,
                                       title='Save the figure')
        try:
            self.lastDir
        except AttributeError:
            self.lastDir = os.curdir

        fname = fs.go(dir_or_file=self.lastDir) # , pattern="*.png")
        if fname is None: # Cancel
            return

        self.lastDir = os.path.dirname(fname)
        try:
            self.canvas.print_figure(fname)
        except IOError as msg:
            err = '\n'.join(map(str, msg))
            msg = 'Failed to save %s: Error msg was\n\n%s' % (
                fname, err)
            error_msg_tkpaint(msg)
backend_tkagg.py 文件源码 项目:PaleoView 作者: GlobalEcologyLab 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def _init_toolbar(self):
        xmin, xmax = self.canvas.figure.bbox.intervalx
        height, width = 50, xmax-xmin
        Tk.Frame.__init__(self, master=self.window,
                          width=int(width), height=int(height),
                          borderwidth=2)

        self.update()  # Make axes menu

        for text, tooltip_text, image_file, callback in self.toolitems:
            if text is None:
                # spacer, unhandled in Tk
                pass
            else:
                button = self._Button(text=text, file=image_file,
                                   command=getattr(self, callback))
                if tooltip_text is not None:
                    ToolTip.createToolTip(button, tooltip_text)

        self.message = Tk.StringVar(master=self)
        self._message_label = Tk.Label(master=self, textvariable=self.message)
        self._message_label.pack(side=Tk.RIGHT)
        self.pack(side=Tk.BOTTOM, fill=Tk.X)
backend_tkagg.py 文件源码 项目:PaleoView 作者: GlobalEcologyLab 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __init__(self, canvas, num, window):
        FigureManagerBase.__init__(self, canvas, num)
        self.window = window
        self.window.withdraw()
        self.set_window_title("Figure %d" % num)
        self.canvas = canvas
        self._num =  num
        if matplotlib.rcParams['toolbar']=='toolbar2':
            self.toolbar = NavigationToolbar2TkAgg( canvas, self.window )
        else:
            self.toolbar = None
        if self.toolbar is not None:
            self.toolbar.update()
        self.canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
        self._shown = False

        def notify_axes_change(fig):
            'this will be called whenever the current axes is changed'
            if self.toolbar != None: self.toolbar.update()
        self.canvas.figure.add_axobserver(notify_axes_change)


问题


面经


文章

微信
公众号

扫码关注公众号