Пример #1
0
def helixmap():
    # Construct our own cubehelix color map.
    from matplotlib._cm import cubehelix
    ch_data=cubehelix(1.0, 0.5, -1.5, 0.0)
    ch_data=cm.revcmap(ch_data)
    helix_map=colors.LinearSegmentedColormap('helix', ch_data, 256)
    return helix_map
Пример #2
0
def _get_mplcolmap_from_file(color_txt_file, reverse=False, ncols=None):
    """
    This reads in a text file of rgb colours,
    (formatted as 3 space-separeted values from 0 to 1 on each line,
    representing r,g,b) and turns them into a matplotlib colormap.

    This is based on a function Neil Kaye found online somewhere.
    """
    LinL = np.loadtxt(color_txt_file)  # 12*3 element array

    b3 = LinL[:, 2]  # n-element list: value of blue at each point.
    b2 = LinL[:, 2]  # Same!
    # position of each of the n values: ranges from 0 to 1
    b1 = np.linspace(0, 1, len(b2))

    # setting up columns for list
    g3 = LinL[:, 1]
    g2 = LinL[:, 1]
    g1 = np.linspace(0, 1, len(g2))

    r3 = LinL[:, 0]
    r2 = LinL[:, 0]
    r1 = np.linspace(0, 1, len(r2))

    # creating list.
    # Each are n-element lists of 3-element tuples
    R = zip(r1, r2, r3)
    G = zip(g1, g2, g3)
    B = zip(b1, b2, b3)

    # transposing list
    # n-element list of 3-element tuples of 3-element tuples
    RGB = zip(R, G, B)
    rgb = zip(*RGB)  # 3-element list of 12-element tuple of 3-element tuples

    # creating dictionary
    keys = ["red", "green", "blue"]
    LinearL = dict(zip(keys, rgb))  # makes a dictionary from 2 lists
    # Value for each key is a 12-element tuple of 3-element tuples.

    if reverse:
        LinearL = mpl_cm.revcmap(LinearL)

    if ncols is None:
        my_cmap = mpl_col.LinearSegmentedColormap("my_colormap", LinearL)
    else:
        my_cmap = mpl_col.LinearSegmentedColormap("my_colormap",
                                                  LinearL,
                                                  N=ncols)

    return my_cmap
Пример #3
0
def dark_gray_cmap(m=0.3, reversed=False):
    '''
    Argument is the maximum brightness.
    '''
    _gray_data = {'red':   ((0., 0., 0.),
                            (1.0, m, m)),
              'green': ((0., 0., 0.),
                        (1.0, m, m)),
              'blue':  ((0., 0., 0.),
                        (1.0, m, m))}
    if reversed:
        _gray_data=cm.revcmap(_gray_data)
    gray_cmap=colors.LinearSegmentedColormap('lightgray', _gray_data, 256)
    return gray_cmap
Пример #4
0
def light_gray_cmap(m=0.3, gamma=1.0, reversed=False):
    '''
    This maps 0 to white (1.0) and 1 to the gray level
    specified by m. The gamma determines whether to darken
    the lower or upper part of the spectrum.
    '''
    def single(x):
        return 1 - m*(x**gamma)

    _gray_data = {'red':   single,
              'green': single,
              'blue':  single}
    if reversed:
        _gray_data=cm.revcmap(_gray_data)
    gray_cmap=colors.LinearSegmentedColormap('lightgray', _gray_data, 256)
    return gray_cmap
Пример #5
0
    _cmaps_data['hot_black_bone'] = _concat_cmap(_cm.afmhot_r, _cm.bone)

# Copied from matplotlib 1.2.0 for matplotlib 0.99 compatibility.
_bwr_data = ((0.0, 0.0, 1.0), (1.0, 1.0, 1.0), (1.0, 0.0, 0.0))
_cmaps_data['bwr'] = _colors.LinearSegmentedColormap.from_list(
    'bwr', _bwr_data)._segmentdata.copy()

################################################################################
# Build colormaps and their reverse.
_cmap_d = dict()

for _cmapname in list(
        _cmaps_data.keys()):  # needed as dict changes within loop
    _cmapname_r = _cmapname + '_r'
    _cmapspec = _cmaps_data[_cmapname]
    _cmaps_data[_cmapname_r] = _cm.revcmap(_cmapspec)
    _cmap_d[_cmapname] = _colors.LinearSegmentedColormap(
        _cmapname, _cmapspec, _cm.LUTSIZE)
    _cmap_d[_cmapname_r] = _colors.LinearSegmentedColormap(
        _cmapname_r, _cmaps_data[_cmapname_r], _cm.LUTSIZE)

################################################################################
# A few transparent colormaps
for color, name in (
    ((1, 0, 0), 'red'),
    ((0, 1, 0), 'blue'),
    ((0, 0, 1), 'green'),
):
    _cmap_d['%s_transparent' % name] = alpha_cmap(color, name=name)
    _cmap_d['%s_transparent_full_alpha_range' % name] = alpha_cmap(color,
                                                                   alpha_min=0,
Пример #6
0
if hasattr(_cm, 'ocean'):
    # MPL 0.99 doesn't have Ocean
    _cmaps_data['ocean_hot'] =  _concat_cmap(_cm.ocean, _cm.hot_r)
if hasattr(_cm, 'afmhot'): # or afmhot
    _cmaps_data['hot_white_bone'] = _concat_cmap(_cm.afmhot, _cm.bone_r)
    _cmaps_data['hot_black_bone'] = _concat_cmap(_cm.afmhot_r, _cm.bone)


################################################################################
# Build colormaps and their reverse.
_cmap_d = dict()

for _cmapname in _cmaps_data.keys():
    _cmapname_r = _cmapname + '_r'
    _cmapspec = _cmaps_data[_cmapname]
    _cmaps_data[_cmapname_r] = _cm.revcmap(_cmapspec)
    _cmap_d[_cmapname] = _colors.LinearSegmentedColormap(
                            _cmapname, _cmapspec, _cm.LUTSIZE)
    _cmap_d[_cmapname_r] = _colors.LinearSegmentedColormap(
                            _cmapname_r, _cmaps_data[_cmapname_r],
                            _cm.LUTSIZE)

################################################################################
# A few transparent colormaps
for color, name in (((1, 0, 0), 'red'),
                    ((0, 1, 0), 'blue'),
                    ((0, 0, 1), 'green'),
                    ):
    _cmap_d['%s_transparent' % name] = alpha_cmap(color, name=name)

Пример #7
0
from matplotlib.colors import LinearSegmentedColormap


def generate_cmap_flame():
    clrs = [(1, 1, 1), (0, 0.3, 1), (0, 1, 1), (0, 1, 0.3), (1, 1, 0),
            (1, 0.5, 0), (1, 0, 0), (0.5, 0, 0)]
    flame = LinearSegmentedColormap.from_list('flame', clrs)
    #flame.set_bad(flame(0)) # set nan's and inf's to white
    flame.set_bad('0.75')  # set nan's and inf's to light gray
    return flame


flame = generate_cmap_flame()

cubehelix = LinearSegmentedColormap('cubehelix',
                                    cm.revcmap(_cm.cubehelix(1, 0, 1, 2.5)))
cubehelix.set_bad(cubehelix(0))


def cmap_powerlaw_adjust(cmap, a):
    '''
    returns a new colormap based on the one given
    but adjusted via power-law:

    newcmap = oldcmap**a
    '''
    if a < 0.:
        return cmap
    cdict = copy(cmap._segmentdata)

    def fn(x):
              'green': ((0.0, 69 / 255., 69 / 255.),
                        (0.5, 0.9990772, 0.9990772),
                        (1.0, 33 / 255., 33 / 255.)
                        ),
              'blue': ((0.0, 0.0, 0.0),
                       (0.5, 0.753402, 0.753402),
                       (1.0, 73 / 255., 73 / 255.)
                       )
              }


# Transform to colormaps
BlOr = mpl.colors.LinearSegmentedColormap('BlOr',
                                          cdict_BlOr,
                                          256)
BlOr_r = cm.revcmap(BlOr._segmentdata)
BlOr_r = mpl.colors.LinearSegmentedColormap('BlOr', BlOr_r, 256)

# mesh = CuboidMesh(nx=21, ny=21,
#                   dx=0.5, dy=0.5,
#                   unit_length=1e-9,
#                   periodicity=(True, True, False)
#                   )

mesh = HexagonalMesh(.5, 41, 41,
                     periodicity=(True, True)
                     )

# Initialise a simulation object and load the skyrmion
# or ferromagnetic states
sim = Sim(mesh, name='neb_21x21-spins_fm-sk_atomic')
Пример #9
0
        (0,0.3,1),
        (0,1,1),
        (0,1,0.3),
        (1,1,0),
        (1,0.5,0),
        (1,0,0),
        (0.5,0,0)
        ]
    flame = LinearSegmentedColormap.from_list('flame', clrs)
    #flame.set_bad(flame(0)) # set nan's and inf's to white
    flame.set_bad('0.75') # set nan's and inf's to light gray
    return flame

flame = generate_cmap_flame()

cubehelix = LinearSegmentedColormap('cubehelix',cm.revcmap(_cm.cubehelix(1,0,1,2.5)))
cubehelix.set_bad(cubehelix(0))

def cmap_powerlaw_adjust(cmap, a):
    '''
    returns a new colormap based on the one given
    but adjusted via power-law:

    newcmap = oldcmap**a
    '''
    if a < 0.:
        return cmap
    cdict = copy(cmap._segmentdata)
    def fn(x):
        return (x[0]**a, x[1], x[2])
    for key in ('red','green','blue'):
Пример #10
0
# Create 2 custom colormaps
cdict_BlOr = {
    'red': (
        (0.0, 1., 1.),
        (0.5, 0.9976163, 0.9976163),
        (1.0, 3 / 255., 3 / 255.),
    ),
    'green': ((0.0, 69 / 255., 69 / 255.), (0.5, 0.9990772, 0.9990772),
              (1.0, 33 / 255., 33 / 255.)),
    'blue':
    ((0.0, 0.0, 0.0), (0.5, 0.753402, 0.753402), (1.0, 73 / 255., 73 / 255.))
}

# Transform to colormaps
BlOr = mpl.colors.LinearSegmentedColormap('BlOr', cdict_BlOr, 256)
BlOr_r = cm.revcmap(BlOr._segmentdata)
BlOr_r = mpl.colors.LinearSegmentedColormap('BlOr', BlOr_r, 256)

# mesh = CuboidMesh(nx=21, ny=21,
#                   dx=0.5, dy=0.5,
#                   unit_length=1e-9,
#                   periodicity=(True, True, False)
#                   )

mesh = HexagonalMesh(.5, 41, 41, periodicity=(True, True))

# Initialise a simulation object and load the skyrmion
# or ferromagnetic states
sim = Sim(mesh, name='neb_21x21-spins_fm-sk_atomic')

sk = '../hexagonal_system/relaxation/npys/2Dhex_41x41_FePd-Ir_B-15e-1_J588e-2_sk-up_npys/m_689.npy'