Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Modifying colormaps (as used in xarray) #16296

Closed
@johnomotani

Description

@johnomotani

xarray's plotting functionality sometimes needs to turn a colormap into a discrete colormap. I came across this in fixing a bugpydata/xarray#3601 wherexarray was ignoring the effects ofset_under(), etc., which had been called on the colormap. We've fixed that problem, but ended up with thishttps://github.com/pydata/xarray/blob/ae6609b025d62a0d863869cbd16db167a8855167/xarray/plot/utils.py#L94-L105

    n_colors = len(levels) + ext_n - 1    pal = _color_palette(cmap, n_colors)    new_cmap, cnorm = mpl.colors.from_levels_and_colors(levels, pal, extend=extend)    # copy the old cmap name, for easier testing    new_cmap.name = getattr(cmap, "name", cmap)    # copy colors to use for bad, under, and over values in case they have been set to    # non-default values    new_cmap._rgba_bad = getattr(cmap, "_rgba_bad", new_cmap._rgba_bad)    new_cmap._rgba_under = getattr(cmap, "_rgba_under", new_cmap._rgba_under)    new_cmap._rgba_over = getattr(cmap, "_rgba_over", new_cmap._rgba_over)

This works, but is not particularly elegant, and if there are any other properties of the originalcmap that we want to keep, we'd have to copy them over explicitly.@dcherian asked me to see if anyone on here could suggest a better way of modifying acmap into a discretecmap?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp