Skip to content

Commit

Permalink
Update deprecated colormap APIs (#583)
Browse files Browse the repository at this point in the history
* Update get_cmap API

* Update get_cmap link in README.md

* Update README.md link

* Update colormap register API

* Update register_cmap link in README.md

* Update get_cmap call

* Update README.md

* Check for existence for backward compatibility

Co-authored-by: Steven G. Johnson <stevenj@mit.edu>

* Update README.md

---------

Co-authored-by: Steven G. Johnson <stevenj@mit.edu>
  • Loading branch information
henry2004y and stevengj authored Jun 10, 2024
1 parent 6c91a61 commit 6ed7f72
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,13 @@ colors in various plot types). In particular:

* Even more general color maps may be defined by passing arrays of (x,y0,y1) tuples for the red, green, blue, and (optionally) alpha components, as defined by the [matplotlib.colors.LinearSegmentedColormap](http://matplotlib.org/api/colors_api.html#matplotlib.colors.LinearSegmentedColormap) constructor, via: `ColorMap{T<:Real}(name::String, r::AbstractVector{(T,T,T)}, g::AbstractVector{(T,T,T)}, b::AbstractVector{(T,T,T)}, n=256, gamma=1.0)` or `ColorMap{T<:Real}(name::String, r::AbstractVector{(T,T,T)}, g::AbstractVector{(T,T,T)}, b::AbstractVector{(T,T,T)}, alpha::AbstractVector{(T,T,T)}, n=256, gamma=1.0)`

* `ColorMap(name::String)` returns an existing (registered) colormap, equivalent to [matplotlib.cm.get_cmap](http://matplotlib.org/api/cm_api.html#matplotlib.cm.get_cmap)(`name`).
* `ColorMap(name::String)` returns an existing (registered) colormap, equivalent to [matplotlib.pyplot.get_cmap](http://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.get_cmap.html#matplotlib-pyplot-get-cmap)(`name`).

* `matplotlib.colors.Colormap` objects returned by Python functions are automatically converted to the `ColorMap` type.

* `get_cmap(name::String)` or `get_cmap(name::String, lut::Integer)` call the [matplotlib.cm.get_cmap](http://matplotlib.org/api/cm_api.html#matplotlib.cm.get_cmap) function.
* `get_cmap(name::String)` or `get_cmap(name::String, lut::Integer)` call the [matplotlib.pyplot.get_cmap](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.get_cmap.html#matplotlib-pyplot-get-cmap) function.

* `register_cmap(c::ColorMap)` or `register_cmap(name::String, c::ColorMap)` call the [matplotlib.cm.register_cmap](http://matplotlib.org/api/cm_api.html#matplotlib.cm.register_cmap) function.
* `register_cmap(c::ColorMap)` or `register_cmap(name::String, c::ColorMap)` call the [matplotlib.colormap.register](https://matplotlib.org/stable/api/cm_api.html#matplotlib.cm.ColormapRegistry.register) function.

* `get_cmaps()` returns a `Vector{ColorMap}` of the currently
registered colormaps.
Expand Down
4 changes: 2 additions & 2 deletions src/colormaps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ function init_colormaps()

copy!(LinearSegmentedColormap, colorsm."LinearSegmentedColormap")

copy!(cm_get_cmap, cm."get_cmap")
copy!(cm_register_cmap, cm."register_cmap")
copy!(cm_get_cmap, haskey(plt, "get_cmap") ? plt."get_cmap" : cm."get_cmap")
copy!(cm_register_cmap, haskey(matplotlib.colormaps, "register") ? matplotlib.colormaps."register" : cm."register_cmap")

copy!(ScalarMappable, cm."ScalarMappable")
copy!(Normalize01, pycall(colorsm."Normalize",PyAny,vmin=0,vmax=1))
Expand Down

0 comments on commit 6ed7f72

Please sign in to comment.