Example #1
0
    def test_make_colormap(self):
        make_colormap([([0, 0, 1], 10), ([1, 1, 1], 10), ([1, 0, 0], 10)],
                      name='french_flag', interpolate=False)
        show_colormaps('french_flag')

        cmap = make_colormap([('dred', 5), ('blue', 2.0), ('orange', 0)],
                             name='my_cmap')
        assert_almost_equal(cmap["red"][1],
                           np.array([0.00392157, 0.62400345, 0.62400345]))

        assert_almost_equal(cmap["blue"][2],
                           np.array([0.00784314, 0.01098901, 0.01098901]))

        assert_almost_equal(cmap["green"][3], np.array([0.01176471, 0.0, 0.0]))
Example #2
0
    def test_make_colormap(self):
        make_colormap(
            [([0, 0, 1], 10), ([1, 1, 1], 10), ([1, 0, 0], 10)],
            name="french_flag",
            interpolate=False,
        )
        show_colormaps("french_flag")

        cmap = make_colormap([("dred", 5), ("blue", 2.0), ("orange", 0)],
                             name="my_cmap")
        assert_almost_equal(cmap["red"][1],
                            np.array([0.00392157, 0.62400345, 0.62400345]))

        assert_almost_equal(cmap["blue"][2],
                            np.array([0.00784314, 0.01098901, 0.01098901]))

        assert_almost_equal(cmap["green"][3], np.array([0.01176471, 0.0, 0.0]))
Example #3
0
def RecoveryPlot(resultarray):

    #Define our bin arrays
    minbin = 14
    maxbin = 22
    bs = .2
    magbins = np.arange(minbin, maxbin + bs, bs)
    magbins = np.array([round(b, 1) for b in magbins])

    mfbins = np.arange(0, 2, .1)
    mfbins = np.array([round(b, 1) for b in mfbins])

    #Gridspec plot
    fig, ax0 = plt.subplots(1, 1, figsize=(12, 5))

    #Subplot for array
    ax0 = plt.gca()

    #Define custom colormap

    mycm = yt.make_colormap([(np.array([88, 88, 88]) / 255, 5),
                             (np.array([51, 8, 94]) / 255, 5), ('dpurple', 5),
                             ('purple', 5), ('dblue', 5), ('blue', 5),
                             (np.array([0, 100, 20]) / 255, 5), ('dgreen', 5),
                             ('green', 5), (np.array([173, 255, 47]) / 255, 5),
                             ('yellow', 5),
                             (np.array([255, 200, 50]) / 255, 5),
                             ('orange', 5), (np.array([255, 69, 0]) / 255, 5),
                             (np.array([168, 0, 0]) / 255, 5),
                             (np.array([84, 0, 0]) / 255, 5)],
                            name='mycm',
                            interpolate=False)

    #Use np.flip and T to set up axes correctly
    im = ax0.imshow(np.flip(resultarray, 1).T,
                    cmap='mycm',
                    extent=(14, 22, 0, 2),
                    aspect='auto')
    ax0.set_xlabel(r'$GALEX$' + ' NUV (mag)', fontsize=25)
    ax0.set_ylabel('Scale Factor', fontsize=25)
    ax0.set_xticks([x for x in np.arange(14, 22, 1)])
    ax0 = WDutils.plotparams(ax0)
    ax0.xaxis.get_major_ticks()[0].set_visible(False)
    ax0.set_xlim(xmin=15, xmax=21)
    ax0.set_yticks([.5, 1, 1.5, 2])
    ax0.yaxis.set_minor_locator(MultipleLocator(.1))

    divider = make_axes_locatable(ax0)
    cax = divider.append_axes("right", size="5%", pad=.1)
    cb = plt.colorbar(im, cax=cax)
    cb.ax.set_ylabel('Recovery Rate (%)', fontsize=25)
    plt.subplots_adjust(bottom=.175, top=.98)
    fig.savefig('RecoveryPlot.svg')
Example #4
0
def colortest(fname,
              name,
              cmap=palettable.cmocean.diverging.Balance_20.mpl_colors,
              mhead=True,
              grids=False,
              show=False,
              fields=['density'],
              linear=False,
              mins=[0.1],
              maxs=[4e7]):
    """Plots the list of fields specified in yt.
    
    Args:
        fname (str): filename to plot.
        cmap (list of tuple): specify mpl colorlist(yt interpolates by default).
        mhead (bool): mark the position of the matchhead.
        grids (bool): overplot the grid structure.
        show (bool): return figure (true) or save to file (false)
        fields (list of str): list of named fields to plot.
        linear (bool): set linear or log scale(false).
        mins (list of float): minima of scale for each field.
        maxs (list of float): maxima of scale for each field.
    
    """
    ds = yt.load(fname)
    size = len(fields)
    fig = plt.figure(figsize=(5 * size, 10))
    grid = AxesGrid(fig, (0.075, 0.075, 0.85, 0.85),
                    nrows_ncols=(1, size),
                    axes_pad=1.2,
                    label_mode="L",
                    share_all=True,
                    cbar_location="right",
                    cbar_mode="each",
                    cbar_size="10%",
                    cbar_pad="0%")
    p = yt.SlicePlot(ds, 'z', list(fields))
    p.set_width((1.2e9, 2 * 1.2e9))
    p.set_center((1.2e9 * 0.5, 0.0))
    #plr = 6e8
    #p.set_width((plr, plr))
    #p.set_center((plr*0.5, plr*4.1))
    p.set_origin(("center", "left", "domain"))
    p.set_axes_unit('cm')
    header = '{} {:10.3f} s'
    if mhead:
        x_match = ds.parameters['x_match']
        y_match = ds.parameters['y_match']
        p.annotate_marker((x_match, y_match),
                          coord_system='plot',
                          plot_args={
                              'color': 'black',
                              's': 30
                          })
    if grids:
        p.annotate_grids()

    _ytcmap = cmap
    cols = [tuple([list(x), 1]) for x in _ytcmap]
    cols.append(([0.0, 0.0, 0.0], 0))
    setcmap = yt.make_colormap(cols, name='custom')
    pvars = zip(fields, mins, maxs)
    for i, (f, mi, mx) in enumerate(pvars):
        if not i:
            p.annotate_title(header.format(name, float(ds.current_time)))
        p.set_cmap(f, 'custom')
        p.set_zlim(f, mi, mx)
        if linear:
            p.set_log(field, False)
        plot = p.plots[f]
        # plot.figure = fig
        plot.axes = grid[i].axes
        plot.cax = grid.cbar_axes[i]
    p._setup_plots()
    if show:
        return fig
    else:
        num = ds.parameter_filename[-5:]
        otpf, _ = os.path.split(ds.fullpath)
        tag = 'colors'
        savn = '{}{}.png'.format(tag, name)
        savf = os.path.join(otpf, "png")
        savp = os.path.join(otpf, "png", tag, savn)
        # build filetree and show or save the figure
        if not os.path.exists(savf):
            os.mkdir(savf)
            os.mkdir(os.path.join(savf, tag))
        elif not os.path.exists(os.path.join(savf, tag)):
            os.mkdir(os.path.join(savf, tag))
        plt.savefig(savp)
        plt.close(fig)
        print("Wrote: {}".format(savp))
Example #5
0
#_cScheme = ('GnBu', 'sequential', 9)
# import cmocean fails for ipyparallel. so hack it through palettable
cmap = palettable.cmocean.sequential.Tempo_20.mpl_colormap
cmap = palettable.cmocean.sequential.Amp_20.mpl_colormap
# import cmocean fails for ipyparallel.
# so hack it through palettable
_ytcmap = palettable.cmocean.sequential.Gray_20.mpl_colors
# _ytcmap = palettable.cmocean.diverging.Curl_19_r.mpl_colors
# _ytcmap = palettable.cmocean.diverging.Curl_19_r.mpl_colors
# _ytcmap = palettable.cmocean.diverging.Delta_20_r.mpl_colors
_ytcmap = palettable.cmocean.diverging.Balance_20.mpl_colors
_ytcmap = palettable.cmocean.sequential.Amp_20.mpl_colors
cols = [tuple([list(x), 1]) for x in _ytcmap]
cols.append(([0.0, 0.0, 0.0], 0))  # black initial color
# cols.append(([1.0, 1.0, 1.0], 0))  # white initial color
setcmap = yt.make_colormap(cols, name='custom')


# yt plotting functions
def planeSlice(fname,
               field,
               lims,
               zcut=0.0,
               linear=False,
               show=False,
               width=1.1e9):
    """Makes a slice at zcut"""
    ds = yt.load(fname)
    p = yt.SlicePlot(ds, 'z', field, center=[0, 0, zcut])
    p.set_width((width, width))
    p.set_cmap(field, 'custom')