Ejemplo n.º 1
0
def multislice(filein, field="Density", fileout='junk.png'):
    pf = load(filein)
    orient = "horizontal"

    fig, axes, colorbars = get_multi_plot(2, 1, colorbar=orient, bw=4)
    #pc = PlotCollection(pf, [0., 0., 0.])
    pc = PlotCollection(pf, [2.4e19, 2.4e19, 2.4e19])

    p = pc.add_slice(field, "x", axes=axes[0][0], use_colorbar=False)
    p.set_cmap("bds_highcontrast")
    #p.modify["velocity"](factor=16)
    p.annotate_velocity(factor=16)

    p = pc.add_slice(field, "y", axes=axes[0][1], use_colorbar=False)
    p.set_cmap("bds_highcontrast")
    #p.show_velocity(factor=16)
    #p = pc.add_slice( field, "z", axes= axes[0][2], use_colorbar=False)
    #p.set_cmap("bds_highcontrast")
    #p.show_velocity(factor=16)

    for p, cax in zip(pc.plots, colorbars):
        cbar = cb.Colorbar(cax, p.image, orientation=orient)
        p.colorbar = cbar
        p._autoset_label()

    fig.savefig(fileout)
Ejemplo n.º 2
0
def plot_2perturbedEnergy_landscape(potential: _perturbedPotentialNDCls,
                                    positions: list,
                                    lambdas: list,
                                    x_range=None,
                                    lam_range=None,
                                    title: str = None,
                                    colbar: bool = False,
                                    ax=None):

    energy_map_lin = []
    for y in lambdas:
        potential.set_lam(y)
        energy_map_lin.append(potential.ene(positions))
    energy_map_lin = np.array(energy_map_lin)

    if (ax == None):
        fig = plt.figure(figsize=(15, 5))
        ax = fig.add_subplot(111)
        colbar = True
    else:
        fig = None

    surf = ax.imshow(
        energy_map_lin,
        cmap="viridis",
        interpolation="nearest",
        origin='center',
        extent=[min(positions),
                max(positions),
                min(lambdas),
                max(lambdas)],
        vmax=100,
        vmin=0,
        aspect="auto")

    if (colbar):
        colorbar.Colorbar(ax, surf, label='Energy')

    if (x_range): ax.set_xlim(min(x_range), max(x_range))
    if (lam_range): ax.set_ylim(min(lam_range), max(lam_range))
    ax.set_xlabel('x')
    ax.set_ylabel('$\lambda$')
    if (title): ax.set_title(title)
    return fig, ax, surf
Ejemplo n.º 3
0
    def _render_on_subplot(self, subplot):
        """
        TESTS:

        A somewhat random plot, but fun to look at::

            sage: x,y = var('x,y')
            sage: contour_plot(x^2-y^3+10*sin(x*y), (x, -4, 4), (y, -4, 4),plot_points=121,cmap='hsv')
            Graphics object consisting of 1 graphics primitive
        """
        from sage.rings.integer import Integer
        options = self.options()
        fill = options['fill']
        contours = options['contours']
        if 'cmap' in options:
            cmap = get_cmap(options['cmap'])
        elif fill or contours is None:
            cmap = get_cmap('gray')
        else:
            if isinstance(contours, (int, Integer)):
                cmap = get_cmap([(i, i, i)
                                 for i in xsrange(0, 1, 1 / contours)])
            else:
                l = Integer(len(contours))
                cmap = get_cmap([(i, i, i) for i in xsrange(0, 1, 1 / l)])

        x0, x1 = float(self.xrange[0]), float(self.xrange[1])
        y0, y1 = float(self.yrange[0]), float(self.yrange[1])

        if isinstance(contours, (int, Integer)):
            contours = int(contours)

        CSF = None
        if fill:
            if contours is None:
                CSF = subplot.contourf(self.xy_data_array,
                                       cmap=cmap,
                                       extent=(x0, x1, y0, y1),
                                       label=options['legend_label'])
            else:
                CSF = subplot.contourf(self.xy_data_array,
                                       contours,
                                       cmap=cmap,
                                       extent=(x0, x1, y0, y1),
                                       extend='both',
                                       label=options['legend_label'])

        linewidths = options.get('linewidths', None)
        if isinstance(linewidths, (int, Integer)):
            linewidths = int(linewidths)
        elif isinstance(linewidths, (list, tuple)):
            linewidths = tuple(int(x) for x in linewidths)

        from sage.plot.misc import get_matplotlib_linestyle
        linestyles = options.get('linestyles', None)
        if isinstance(linestyles, (list, tuple)):
            linestyles = [
                get_matplotlib_linestyle(l, 'long') for l in linestyles
            ]
        else:
            linestyles = get_matplotlib_linestyle(linestyles, 'long')
        if contours is None:
            CS = subplot.contour(self.xy_data_array,
                                 cmap=cmap,
                                 extent=(x0, x1, y0, y1),
                                 linewidths=linewidths,
                                 linestyles=linestyles,
                                 label=options['legend_label'])
        else:
            CS = subplot.contour(self.xy_data_array,
                                 contours,
                                 cmap=cmap,
                                 extent=(x0, x1, y0, y1),
                                 linewidths=linewidths,
                                 linestyles=linestyles,
                                 label=options['legend_label'])
        if options.get('labels', False):
            label_options = options['label_options']
            label_options['fontsize'] = int(label_options['fontsize'])
            if fill and label_options is None:
                label_options['inline'] = False
            subplot.clabel(CS, **label_options)
        if options.get('colorbar', False):
            colorbar_options = options['colorbar_options']
            from matplotlib import colorbar
            cax, kwds = colorbar.make_axes_gridspec(subplot,
                                                    **colorbar_options)
            if CSF is None:
                cb = colorbar.Colorbar(cax, CS, **kwds)
            else:
                cb = colorbar.Colorbar(cax, CSF, **kwds)
                cb.add_lines(CS)
Ejemplo n.º 4
0
    def _render_on_subplot(self, subplot):
        """
        TESTS::

            sage: matrix_plot(random_matrix(RDF, 50), cmap='jet')
        """
        options = self.options()
        cmap = get_cmap(options.pop('cmap', None))
        origin = options['origin']

        norm = options['norm']

        if norm == 'value':
            import matplotlib
            norm = matplotlib.colors.NoNorm()

        if options['subdivisions']:
            subdiv_options = options['subdivision_options']
            if isinstance(subdiv_options['boundaries'], (list, tuple)):
                rowsub, colsub = subdiv_options['boundaries']
            else:
                rowsub = subdiv_options['boundaries']
                colsub = subdiv_options['boundaries']
            if isinstance(subdiv_options['style'], (list, tuple)):
                rowstyle, colstyle = subdiv_options['style']
            else:
                rowstyle = subdiv_options['style']
                colstyle = subdiv_options['style']
            if rowstyle is None:
                rowstyle = dict()
            if colstyle is None:
                colstyle = dict()

            # Make line objects for subdivisions
            from line import line2d
            lim = self.get_minmax_data()
            # First draw horizontal lines representing row subdivisions
            for y in rowsub:
                l = line2d([(lim['xmin'], y - 0.5), (lim['xmax'], y - 0.5)],
                           **rowstyle)[0]
                l._render_on_subplot(subplot)
            for x in colsub:
                l = line2d([(x - 0.5, lim['ymin']), (x - 0.5, lim['ymax'])],
                           **colstyle)[0]
                l._render_on_subplot(subplot)

        if hasattr(self.xy_data_array, 'tocoo'):
            # Sparse matrix -- use spy
            opts = options.copy()
            for opt in [
                    'vmin', 'vmax', 'norm', 'origin', 'subdivisions',
                    'subdivision_options', 'colorbar', 'colorbar_options'
            ]:
                del opts[opt]
            if origin == 'lower':
                subplot.spy(self.xy_data_array.tocsr()[::-1], **opts)
            else:
                subplot.spy(self.xy_data_array, **opts)
        else:
            opts = dict(cmap=cmap,
                        interpolation='nearest',
                        aspect='equal',
                        norm=norm,
                        vmin=options['vmin'],
                        vmax=options['vmax'],
                        origin=origin,
                        zorder=options.get('zorder', None))
            image = subplot.imshow(self.xy_data_array, **opts)

            if options.get('colorbar', False):
                colorbar_options = options['colorbar_options']
                from matplotlib import colorbar
                cax, kwds = colorbar.make_axes_gridspec(
                    subplot, **colorbar_options)
                cb = colorbar.Colorbar(cax, image, **kwds)

        if origin == 'upper':
            subplot.xaxis.tick_top()
        elif origin == 'lower':
            subplot.xaxis.tick_bottom()
        subplot.xaxis.set_ticks_position(
            'both')  #only tick marks, not tick labels
Ejemplo n.º 5
0
months = MonthLocator()  # every month
yearsFmt = DateFormatter('%Y')

# format the ticks
ax.xaxis.set_major_locator(years)
ax.xaxis.set_major_formatter(yearsFmt)
ax.yaxis.set_ticks([])
#ax.xaxis.set_minor_locator(months)

#LIMITS AND LABELS
ax.set_xlim((727809.0, 735110.0))
ax.set_ylim([-0.3, y + 0.3])
ax.set_xlabel("Time (yr)")

fig.autofmt_xdate()
for tick in ax.xaxis.get_major_ticks():
    tick.label.set_fontsize(ticklabelsize)

#COLORBAR
cax, kw = clbr.make_axes(ax)
clr = clbr.Colorbar(cax, colorbarim)
clr.set_label('Mass Balance (m w. eq. yr' + "$\mathregular{^{-1})}$",
              size=ticklabelsize)
clr.ax.tick_params(labelsize=10)
clr.ax.set_aspect(30)

if type(outputfile) == str:
    fig.savefig(outputfile, dpi=500)
    plt.close()
if show:
    plt.show()
                                 "GADGET 750 Myr",
                                 text_args={
                                     'color': 'k'
                                 })
        if time == 4:
            if ax == 0:
                p.modify["text"]((0.1, 0.9),
                                 "GADGET 1000 Myr",
                                 text_args={
                                     'color': 'k'
                                 })

        p.set_width(30, 'kpc')

    # Add colorbar
    for p, cax in zip(pc.plots, colorbars):
        cbar = cb.Colorbar(cax, p.image, orientation='horizontal')
        p.colorbar = cbar
        p._autoset_label()

    if time == 0:
        fig.savefig("Gadget_Todoroki_0Myr_Sigma")
    if time == 1:
        fig.savefig("Gadget_Todoroki_250Myr_Sigma")
    if time == 2:
        fig.savefig("Gadget_Todoroki_500Myr_Sigma")
    if time == 3:
        fig.savefig("Gadget_Todoroki_750Myr_Sigma")
    if time == 4:
        fig.savefig("Gadget_Todoroki_1000Myr_Sigma")
Ejemplo n.º 7
0
                    p.modify["text"]((0.1,0.9),"Enzo 250 Myr",text_args={'color':'w'})
            if time == 2:
                if ax == 0:
                    p.modify["text"]((0.1,0.9),"Enzo 500 Myr",text_args={'color':'w'})
            if time == 3:
                if ax == 0:
                    p.modify["text"]((0.1,0.9),"Enzo 750 Myr",text_args={'color':'w'})
            if time == 4:
                if ax == 0:
                    p.modify["text"]((0.1,0.9),"Enzo 1000 Myr",text_args={'color':'w'})

            pc.set_width(30,'kpc')

        # Add colorbar
        for p, cax in zip(pc.plots, colorbars):
            cbar=cb.Colorbar(cax,p.image,orientation='horizontal')
            p.colorbar=cbar
            p._autoset_label()

        if time == 0:
            fig.savefig("Enzo_0Myr_Sigma")
        if time == 1:
            fig.savefig("Enzo_250Myr_Sigma")
        if time == 2:
            fig.savefig("Enzo_500Myr_Sigma")
        if time == 3:
            fig.savefig("Enzo_750Myr_Sigma")
        if time == 4:
            fig.savefig("Enzo_1000Myr_Sigma")

        # Plot projected cell size weighted by inverse square of cell V (c/o Sam Leitner)    
Ejemplo n.º 8
0
    def plot(self, fig=None):
        """
        Creates a matplotlib window to display the frame
        Adds a small window which is a zoom on where the cursor is
        """
        # Peut-être faire une classe Plot() qui se chargera de tout, et faire que plot() appelle Plot().
        # https://matplotlib.org/examples/animation/subplots.html
        # Defining the grid on which the plot will be shown
        grid = gridspec.GridSpec(6, 2)
        if fig is None:
            fig = plt.figure(num="HRS Frame visualisation",
                             figsize=(9.6, 6.4), clear=True)
        self.fig = fig
        self.ax1 = fig.add_subplot(grid[:-1, 0])
        self.ax2 = fig.add_subplot(grid[0:3, 1])
        self.ax3 = fig.add_subplot(grid[3:, 1], label='x')
        self.ax4 = fig.add_subplot(grid[3:, 1], label='y', frameon=False)
        cbax1 = fig.add_subplot(grid[-1, 0])
        fig.subplots_adjust(wspace=0.3, hspace=2.2)

        # Convenience names
        ax1 = self.ax1
        ax2 = self.ax2
        ax3 = self.ax3
        ax3.color = 'xkcd:cerulean'
        ax4 = self.ax4
        ax4.color = 'xkcd:tangerine'
        data = self.data
        zoom = self._zoom1

        # Adding the plots
        self.plot1 = ax1.imshow(data, vmin=self.dataminzs, vmax=self.datamaxzs)
        ax1.title.set_text('CCD')
        cb.Colorbar(ax=cbax1, mappable=self.plot1, orientation='horizontal', ticklocation='bottom')
        zoomeddata = self.data[
            np.int(self.data.shape[0]//2)-zoom:np.int(self.data.shape[0]//2)+zoom,
            np.int(self.data.shape[1]//2)-zoom:np.int(self.data.shape[1]//2)+zoom
            ]
        self.plot2 = ax2.imshow(zoomeddata, vmin=self.dataminzs, vmax=self.datamaxzs)
        # We need to tidy the bottom right plot a little bit first
        # Ax3 first
        self.ax3.tick_params(axis='x', colors=ax3.color)
        self.ax3.tick_params(axis='y', colors=ax3.color)
        self.ax3.xaxis.tick_bottom()
        self.ax3.yaxis.tick_left()
        self.ax3.set_xlabel('Pixel', color=ax3.color)
        self.ax3.set_ylabel('Intensity', color=ax3.color)
        self.ax3.xaxis.set_label_position('bottom')
        self.ax3.yaxis.set_label_position('left')
        # Ax4
        self.ax4.tick_params(axis='x', colors=ax4.color)
        self.ax4.tick_params(axis='y', colors=ax4.color)
        self.ax4.xaxis.tick_top()
        self.ax4.yaxis.tick_right()
        self.ax4.set_xlabel('Pixel', color=ax4.color)
        self.ax4.set_ylabel('Intensity', color=ax4.color)
        self.ax4.xaxis.set_label_position('top')
        self.ax4.yaxis.set_label_position('right')

        self.ax3.plot(self.data[:, np.int(self.data.shape[1]/2)], color=ax3.color)
        self.ax4.plot(self.data[np.int(self.data.shape[0]/2), :], color=ax4.color)
        ax1.figure.canvas.mpl_connect('motion_notify_event', self._zoom)
        ax1.figure.canvas.mpl_connect('button_press_event', self._plot)
        plt.show()