示例#1
0
    def __init__(self, data, toplevel):
        """
        *Initialize with:*

        Args:
            data (GlobalData Object): Source of Data
        """
        super(PlotArea, self).__init__()
        self.toplevel = toplevel
        # GlobalData
        self.data = data
        # look_at_head: index-_bufsize:index -> the data you gonna display
        self.look_at_head = 0
        # look at present?
        self.look_at_present = True
        # number of points in buffer
        self._bufsize = int(100)
        # scrol Window Adjustments
        self.adj_scroll_hist = None
        self.axisequal = False
        #
        self.BufSizeSpinnBtn = None

        # MPL:
        # create figure
        self.figure = Figure()
        # create axes
        self.axx = self.figure.add_subplot(111)
        # set grid
        self.axx.grid(True)
        # set equal scale
        self.axx.set_aspect('auto')
        # set dynamic canvas to GTK3AGG backend
        self.canvas = FigureCanvasGTK3Agg(self.figure)
        # init plots
        self.points = {}
        self.nartist = 16
        self.nMarkers = 7
        # set the first 7 artists as Markers instead of lines
        for artist in range(self.nMarkers):
            self.points[artist] = self.axx.plot(nan, nan, 'ko')[0]
        for artist in range(self.nMarkers, self.nartist):
            self.points[artist] = self.axx.plot(nan, nan, '-')[0]

        # GTK:
        vbox = Gtk.VBox(False, 3)
        self.add(vbox)
        # Get PlotWindow and connect to figure
        self.plot_win = Gtk.Viewport()
        self.plot_win.add(self.canvas)

        self.buffer_win = Gtk.Viewport()
        vbox.pack_start(self.plot_win, True, True, 0)
        vbox.pack_start(self.buffer_win, False, True, 1)
        self._init_buffer_box()

        # ######
        # finally show
        self.canvas.show()
        self.show_all()
示例#2
0
    def __init__(self, data_file,
                plot_groups = [1],
                data_type = 2,
                color_map = 'jet',
                plot_contours = False,
                face_colour = "white",
                filled_contours = False,
                plot_label = "",
                plot_bands = None,
                time_zone = 0,
                plot_max_freq = 30.0,
                run_quietly = False,
                save_file = '',
                dpi=150,
                parent = None,
                user_bands=None,
                datadir=None):


        """
        user_bands - a list of bands to be displayed.
        """
        self.data_type = data_type
        self.run_quietly = run_quietly
        self.dpi=dpi
        self.plot_filled_contours = filled_contours
        self.df = VOAOutFile(data_file, time_zone=time_zone, data_type=self.data_type, quiet=run_quietly)

        self.image_defs = self.IMG_TYPE_DICT[self.data_type]
        self.user_bands = user_bands
        portland = ListedColormap(["#0C3383", "#0b599b","#0a7fb4","#57a18f","#bec255","#f2c438","#f2a638","#ef8235","#e4502a","#d91e1e"])
        matplotlib.cm.register_cmap(name='portland', cmap=portland)

        if plot_groups[0]=='a':
            num_grp = self.df.get_number_of_groups()
            plot_groups = list(range(0,num_grp))

        number_of_subplots = len(plot_groups)

        #matplotlib.rcParams['mpl_toolkits.legacy_colorbar'] = False

        matplotlib.rcParams['axes.edgecolor'] = 'gray'
        matplotlib.rcParams['axes.facecolor'] = 'white'
        matplotlib.rcParams['axes.grid'] = True
        matplotlib.rcParams['grid.alpha'] = 0.4
        matplotlib.rcParams['legend.fancybox'] = True
        matplotlib.rcParams['legend.shadow'] = True
        matplotlib.rcParams['figure.subplot.hspace'] = 0.45
        matplotlib.rcParams['figure.subplot.wspace'] = 0.35
        matplotlib.rcParams['figure.subplot.right'] = 0.85
        colorbar_fontsize = 12

        if number_of_subplots <= 1:
            num_rows = 1
            self.main_title_fontsize = 24
            matplotlib.rcParams['legend.fontsize'] = 12
            matplotlib.rcParams['axes.labelsize'] = 12
            matplotlib.rcParams['axes.titlesize'] = 8
            matplotlib.rcParams['xtick.labelsize'] = 10
            matplotlib.rcParams['ytick.labelsize'] = 10
            matplotlib.rcParams['figure.subplot.top'] = 0.79 # single figure plots have a larger title so require more space at the top.
            self.x_axes_ticks = np.arange(0,25,2)
        elif ((number_of_subplots >= 2) and (number_of_subplots <= 6 )):
            num_rows = 2
            self.main_title_fontsize = 18
            matplotlib.rcParams['legend.fontsize'] = 10
            matplotlib.rcParams['axes.labelsize'] = 10
            matplotlib.rcParams['axes.titlesize'] = 11
            matplotlib.rcParams['xtick.labelsize'] = 8
            matplotlib.rcParams['ytick.labelsize'] = 8
            self.x_axes_ticks = np.arange(0,25,4)
        else:
            num_rows = 3
            self.main_title_fontsize = 16
            matplotlib.rcParams['legend.fontsize'] = 8
            matplotlib.rcParams['axes.labelsize'] = 8
            matplotlib.rcParams['axes.titlesize'] = 10
            matplotlib.rcParams['xtick.labelsize'] = 6
            matplotlib.rcParams['ytick.labelsize'] = 6
            self.x_axes_ticks = np.arange(0,25,4)

        num_cols = int(math.ceil(float(number_of_subplots)/float(num_rows)))
        fig = plt.figure()
        axgr = AxesGrid(fig, 111,
                    nrows_ncols=(num_rows, num_cols),
                    axes_pad=0.6,
                    cbar_location='right',
                    cbar_mode='single',
                    cbar_pad=0.2,
                    cbar_size='3%',
                    label_mode='')

        self.main_title_label = fig.suptitle(plot_label+str(self.image_defs['title']), fontsize=self.main_title_fontsize)

        for ax, chan_grp in zip(axgr, plot_groups):
            (group_name, group_info, fot, muf, hpf, image_buffer) = self.df.get_group_data(chan_grp)

            if number_of_subplots > 4:
                #save a little space by only labelling the outer edges of the plot
                ax.label_outer()

            _sign = '+' if (time_zone >= 0) else ''
            self.x_label = ax.set_xlabel(_('Time (UTC%(sig)s%(tz)s)') % {'sig':_sign, 'tz':time_zone})
            self.y_label = ax.set_ylabel(_('Frequency (MHz)'))

            ## Autoscale y (frequency axis)
            if (plot_max_freq==self.AUTOSCALE) :
                y_max = math.ceil(max(muf) / 5.0) * 5.0
                y_max = min(plot_max_freq, 30.0)
                y_max = max(plot_max_freq, 5.0)
            else :
                y_max = math.ceil(plot_max_freq / 5.0) * 5.0
            image_buffer = image_buffer[0:int(y_max-1),:]

            y_ticks = [2, 5]
            for y_tick_value in np.arange(10, y_max+1, 5):
                y_ticks.append(y_tick_value)

            ax.plot(list(range(0, 25)), muf,'r-', list(range(0, 25)), fot, 'g-')
            ax.set_ylim([2, y_max])

            ax.set_xticks(self.x_axes_ticks)
            ax.set_yticks(y_ticks)

            self.add_legend(ax)
            title_str = group_info.strip()
            if number_of_subplots > 1:
                title_str = self.get_small_title(title_str)
            self.subplot_title_label = ax.set_title(title_str, multialignment='left', **self.mono_font)

            if (self.data_type > 0):
                if (self.plot_filled_contours):
                    im = ax.contourf(image_buffer,
                        self.image_defs['y_labels'],
                        extent=(0, 24, 2, y_max),
                        cmap=color_map)
                    plot_contours =True
                else:
                    im = ax.imshow(image_buffer, interpolation='bicubic',
                        extent=(0, 24, 2, y_max),
                        origin = 'lower',
                        cmap=color_map,
                        alpha = 0.95,
                        norm = matplotlib.colors.Normalize(clip = False,
                        vmin=self.image_defs['min'],
                        vmax=self.image_defs['max']))
                if plot_contours:
                    ax.contour(image_buffer, self.image_defs['y_labels'][1:], extent=(0, 24, 2, y_max), linewidths=1.0, colors='k', alpha=0.6)

            if plot_bands:
                for a,b in plot_bands:
                    ax.axhspan(a, b, alpha=0.5, ec='k', fc='k')

            if self.user_bands:
                for ch in self.user_bands:
                    ax.axhspan(ch-0.04, ch+0.04, alpha=0.5, ec='0.5', fc='0.5')

        # Hide any unused subplots
        for ax in axgr[number_of_subplots:]:
            ax.set_visible(False)

        if (self.data_type > 0):
            axgr.cbar_axes[0].colorbar(im,
                    format = FuncFormatter(eval('self.'+self.image_defs['formatter'])))
            #for t in self.cb_ax.get_yticklabels():
            ###    t.set_fontsize(colorbar_fontsize)

        if save_file :
            fig.savefig(save_file, dpi=self.dpi, facecolor=fig.get_facecolor(), edgecolor='none')

        if not self.run_quietly:
            canvas = FigureCanvasGTK3Agg(fig)
            canvas.show()
            dia = VOAPlotWindow('pythonProp - ' + self.image_defs['title'],
                        canvas,
                        parent=parent,
                        dpi=self.dpi,
                        datadir=datadir)
        return
示例#3
0
    def __init__(self, main_window=None, nbp=0):

        Gtk.VBox.__init__(self)

        self._main_window = main_window

        self.figure = Figure(facecolor='#474747', edgecolor='#474747')
        self.canvas = FigureCanvasGTK3Agg(self.figure)  # a Gtk.DrawingArea

        # --- Flag for primary axis time format
        self.xtime = False

        # --- The primary axis
        self.axis = self.figure.add_subplot(111)

        # --- The secondary y-axis (hidden by default)
        self.secondary_axis = self.axis.twinx()
        self.secondary_axis.set_frame_on(False)
        self.show_secondary_axis = True
        self.hide_secondary_axis()

        # --- A dummy secondary x axis for mousover events
        self.dummy_axis = self.axis.twiny()
        self.dummy_axis.set_frame_on(False)
        self.dummy_axis.set_xticks([])
        self.set_dummy_xlim()

        self.cb = None
        self.nbp = nbp

        # Init some globals for getting the mouse position in the client
        # application
        self.inaxes = False
        self.mouse_x = 0
        self.mouse_y = 0

        hbox = Gtk.HBox(spacing=4)

        self.r_label = Gtk.Label("0.0 | ")
        self.z_label = Gtk.Label("| 0.0")
        self.spacer = Gtk.Label("|")
        self.reset_b = Gtk.Button("Reset Zoom")
        self.settings_b = Gtk.Button("Settings")

        self.pack_start(self.canvas, True, True, 0.0)
        self.pack_start(hbox, False, False, 0.0)
        hbox.pack_end(self.r_label, False, False, 0.0)
        hbox.pack_end(self.spacer, False, False, 0.0)
        hbox.pack_end(self.z_label, False, False, 0.0)
        hbox.pack_end(self.reset_b, False, False, 0.0)
        hbox.pack_start(self.settings_b, False, False, 0.0)

        # --- Variables for zooming --- #
        self.holddown = False
        self.zoom_flag = False
        self.box_start = None
        self.box_start_px = None
        self.box_end = None
        self.zoom_box = None
        self.zoomlimits = [0., 1., 0., 1.]
        self.maxlimits = []
        self.autoscale_old = [True, True]

        # --- Container for flags to show certain legend entries -- #
        self.show_legend_entries = np.array([], 'bool')

        # --- Connections --- #
        self.canvas.mpl_connect("motion_notify_event", self.mouse_move)
        self.canvas.mpl_connect("scroll_event", self.mouse_scroll)
        self.canvas.mpl_connect("button_press_event", self.button_pressed)
        self.canvas.mpl_connect("button_release_event", self.button_released)
        self.reset_b.connect("clicked", self.zoom_out)
        self.settings_b.connect("clicked", self.change_settings)
        self.canvas.mpl_connect("axes_enter_event", self.axes_enter_callback)
        self.canvas.mpl_connect("axes_leave_event", self.axes_leave_callback)
        self.canvas.mpl_connect("draw_event", self.draw_event)

        self.set_settings(generate_default_settings())

        # Create a plotsettings dictionary as a copy of the current plot settings
        # Redundand, but a quick workaround for keeping the marker size and linewidth
        # even if settings were loaded without any plots
        self.main_plot_settings = self.get_settings()
示例#4
0
    def __init__(self, data_file, 
                data_type = 2,
                color_map = 'jet',
                plot_label = "",
                time_zone = 0, 
                plot_max_freq = 30.0,
                run_quietly = False,
                save_file = '',
                parent = None):

        self.data_type = data_type
        self.data_file = VOAOutFile(data_file, \
                        time_zone=time_zone, \
                        data_type=self.data_type)

        self.image_defs = self.IMG_TYPE_DICT[self.data_type]
        
        #color_map = eval('P.cm.' + color_map)
    
        num_grp = self.data_file.get_number_of_groups()
        if num_grp < 2:
            md = Gtk.MessageDialog(parent, \
                Gtk.DialogFlags.MODAL,\
                Gtk.MessageType.ERROR, \
                Gtk.ButtonsType.CANCEL, \
                "There must be 2 groups or more")
            md.run()
            md.destroy()
            return
        plot_groups = list(range(0, num_grp))

        self.subplots = []
        number_of_subplots = len(plot_groups)
        
        matplotlib.rcParams['axes.edgecolor'] = 'gray'
        matplotlib.rcParams['axes.facecolor'] = 'white'
        matplotlib.rcParams['axes.grid'] = True
        matplotlib.rcParams['figure.facecolor'] = 'white'
        matplotlib.rcParams['legend.fancybox'] = True
        matplotlib.rcParams['legend.shadow'] = True
        matplotlib.rcParams['figure.subplot.hspace'] = 0.45
        matplotlib.rcParams['figure.subplot.wspace'] = 0.35
        matplotlib.rcParams['figure.subplot.right'] = 0.85
        colorbar_fontsize = 12
               
        self.main_title_fontsize = 24
        matplotlib.rcParams['legend.fontsize'] = 12
        matplotlib.rcParams['axes.labelsize'] = 12
        matplotlib.rcParams['axes.titlesize'] = 10
        matplotlib.rcParams['xtick.labelsize'] = 10
        matplotlib.rcParams['ytick.labelsize'] = 10
        self.x_axes_ticks = np.arange(0, 25, 2)

        self.fig = Figure()
        ax = Axes3D(self.fig)
        
        X = np.arange(0, 25)
        Y = np.arange(0, len(plot_groups))
        X, Y = np.meshgrid(X, Y)

        data_buffer = [] # hold the Z data sets


        for chan_grp in plot_groups:
            (group_name, group_info, fot, muf, hpf, image_buffer) = \
                self.data_file.get_group_data(chan_grp)
            # Copy the element at [0] to the tail of the array 
            #to 'wrap-around' the values at 24hrs.
            np.resize(muf, len(muf)+1)
            muf[-1] = muf[0]
            data_buffer.append(muf)

        Z = np.vstack((tuple(data_buffer)))

	# set up the titles and labels
        ax.set_xticks(np.arange(0, 25, 2))

        if (plot_max_freq==self.AUTOSCALE) :
            z_max = math.ceil(max(muf) / 5.0) * 5.0
            z_max = min(plot_max_freq, 30.0)
            z_max = max(plot_max_freq, 5.0)
        else :
            z_max = math.ceil(plot_max_freq / 5.0) * 5.0
        z_ticks = [2, 5]
        for z_tick_value in np.arange(10, z_max+1, 5):
            z_ticks.append(z_tick_value) 
        #ax.set_yticks(z_ticks)

	#label axes
        tz_sign = '+' if (time_zone >= 0) else ''
        self.x_label = ax.set_xlabel('Time (UTC%s%s)' % (tz_sign, time_zone))
        self.y_label = ax.set_ylabel('Group')
        self.z_label = ax.set_zlabel('Frequency (MHz)')

	#do the plot
        ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=color_map)
        canvas = FigureCanvasGTK3Agg(self.fig)
        canvas.show()
        Axes3D.mouse_init(ax)
        VOAPlotWindow('pythonProp - ' + self.image_defs['title'], \
                        canvas, \
                        parent)
        return
	return r


phi = numpy.linspace(0, 2 * numpy.pi, 1024)
m_init = 3
n1_init = 2
n2_init = 18
n3_init = 18


fig = Figure((6, 6), dpi = 80)
ax = fig.add_subplot(111, polar = True)

r = supershape_radius(phi, 1, 1, m_init, n1_init, n2_init, n3_init)
lines, = ax.plot(phi, r, lw = 3.)


win = Gtk.Window()
win.connect('delete-event', Gtk.main_quit)
win.set_title('SuperShape')

canvas = FigureCanvasGTK3Agg(fig)
w, h = fig.get_size_inches()
dpi_res = fig.get_dpi()
w, h = int(numpy.ceil(w * dpi_res)), int(numpy.ceil(h * dpi_res))
canvas.set_size_request(w, h)
win.add(canvas)

win.show_all()
Gtk.main()