Skip to content

Commit 6ed7f72

Browse files
henry2004ystevengj
andauthored
Update deprecated colormap APIs (#583)
* 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 <[email protected]> * Update README.md --------- Co-authored-by: Steven G. Johnson <[email protected]>
1 parent 6c91a61 commit 6ed7f72

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,13 @@ colors in various plot types). In particular:
205205

206206
* 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)`
207207

208-
* `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`).
208+
* `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`).
209209

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

212-
* `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.
212+
* `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.
213213

214-
* `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.
214+
* `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.
215215

216216
* `get_cmaps()` returns a `Vector{ColorMap}` of the currently
217217
registered colormaps.

src/colormaps.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ function init_colormaps()
5454

5555
copy!(LinearSegmentedColormap, colorsm."LinearSegmentedColormap")
5656

57-
copy!(cm_get_cmap, cm."get_cmap")
58-
copy!(cm_register_cmap, cm."register_cmap")
57+
copy!(cm_get_cmap, haskey(plt, "get_cmap") ? plt."get_cmap" : cm."get_cmap")
58+
copy!(cm_register_cmap, haskey(matplotlib.colormaps, "register") ? matplotlib.colormaps."register" : cm."register_cmap")
5959

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

0 commit comments

Comments
 (0)