Skip to content

Add custom colormap and colorbar ticklabels  #72

@gewitterblitz

Description

@gewitterblitz

Hi,

I have two questions:

Is it possible to use custom colormaps in xrviz without changing too much of base code?

Here's my implementation of an animation using an xarray dataset:

import xarray as xr
from xrviz.dashboard import Dashboard

data = xr.open_mfdataset('./*.nc',parallel=True)


hid_colors = ['#D7CCC8', 'FFCCBC', 'FF8A65', 'BF360C', 'F44336',
              'FFEE58', '94D82D', '51CF66', '2B8A3E', '66D9E8',
              '228BE6', '364FC7', 'EEBEFA', 'F783AC', 'F8F9FA',
              'F8F9FA','F8F9FA','F8F9FA']


cmaphid_colors = [hex_to_rgb(color) for color in hid_colors]
cmaphid = [[t/255 for t in x] for x in cmaphid_colors]

cmapncarpid = colors.ListedColormap(cmaphid)
plt.register_cmap(name='ncarpid',cmap=cmapncarpid)

initial_params = {# Select Variable
                  'Variables': 'PID',

                  # Set Coords
                  'Set Coords': ['lat0', 'lon0'],

                  # Axes
                  'x': 'lon0',
                  'y': 'lat0',
                  'z': 'animate',

                  # Style
                  'height': 300,
                  'width': 650,
                  'colorbar': True,
                  'cmap': 'ncarpid'     
}

However, when I use the custom cmap ncarpid, it is not recognized by xrviz.

Also, is there a way to replace default colorbar ticklabels with strings of our choice?

Here's an example of the dashboard generated from code snippet above:

Screen Shot 2020-11-10 at 1 43 43 PM

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions