colormaps module¶
leafmap.colormaps
¶
Module for commonly used colormaps and palettes for visualizing geospatial data.
create_colormap(cmap='gray', colors=None, discrete=False, label=None, width=8.0, height=0.4, orientation='horizontal', vmin=0, vmax=1.0, axis_off=False, show_name=False, font_size=12, **kwargs)
¶
Plot a matplotlib colormap.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmap
|
str
|
Matplotlib colormap. Defaults to "gray". See https://matplotlib.org/3.3.4/tutorials/colors/colormaps.html#sphx-glr-tutorials-colors-colormaps-py for options. |
'gray'
|
colors
|
list
|
A list of custom colors to create a colormap. Defaults to None. |
None
|
discrete
|
bool
|
Whether to create a discrete colorbar. Defaults to False. |
False
|
label
|
str
|
Label for the colorbar. Defaults to None. |
None
|
width
|
float
|
The width of the colormap. Defaults to 8.0. |
8.0
|
height
|
float
|
The height of the colormap. Defaults to 0.4. |
0.4
|
orientation
|
str
|
The orientation of the colormap. Defaults to "horizontal". |
'horizontal'
|
vmin
|
float
|
The minimum value range. Defaults to 0. |
0
|
vmax
|
float
|
The maximum value range. Defaults to 1.0. |
1.0
|
axis_off
|
bool
|
Whether to turn axis off. Defaults to False. |
False
|
show_name
|
bool
|
Whether to show the colormap name. Defaults to False. |
False
|
font_size
|
int
|
Font size of the text. Defaults to 12. |
12
|
get_colorbar(colors, vmin=0, vmax=1, width=6.0, height=0.4, orientation='horizontal', discrete=False)
¶
Creates a colorbar based on custom colors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
colors
|
list
|
A list of hex colors. |
required |
vmin
|
float
|
The minimum value range. Defaults to 0. |
0
|
vmax
|
float
|
The maximum value range. Defaults to 1.0. |
1
|
width
|
float
|
The width of the colormap. Defaults to 6.0. |
6.0
|
height
|
float
|
The height of the colormap. Defaults to 0.4. |
0.4
|
orientation
|
str
|
The orientation of the colormap. Defaults to "horizontal". |
'horizontal'
|
discrete
|
bool
|
Whether to create a discrete colormap. |
False
|
get_palette(cmap_name=None, n_class=None, hashtag=False)
¶
Get a palette from a matplotlib colormap. See the list of colormaps at https://matplotlib.org/stable/tutorials/colors/colormaps.html.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmap_name
|
str
|
The name of the matplotlib colormap. Defaults to None. |
None
|
n_class
|
int
|
The number of colors. Defaults to None. |
None
|
hashtag
|
bool
|
Whether to return a list of hex colors. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
List[str]
|
A list of hex colors. |
list_colormaps(add_extra=False, lowercase=False)
¶
List all available colormaps. See a complete lost of colormaps at https://matplotlib.org/stable/tutorials/colors/colormaps.html.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
add_extra
|
bool
|
If True, include additional colormaps, Default False, |
False
|
lowercase
|
bool
|
If True, convert colormaps names to lowercase, Default is False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
List
|
The list of colormap names. |
plot_colormap(cmap='gray', colors=None, discrete=False, label=None, width=3.0, height=0.25, orientation='horizontal', vmin=0, vmax=1.0, axis_off=False, show_name=False, font_size=12, **kwargs)
¶
Plot a matplotlib colormap.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmap
|
str
|
Matplotlib colormap. Defaults to "gray". See https://matplotlib.org/3.3.4/tutorials/colors/colormaps.html#sphx-glr-tutorials-colors-colormaps-py for options. |
'gray'
|
colors
|
list
|
A list of custom colors to create a colormap. Defaults to None. |
None
|
discrete
|
bool
|
Whether to create a discrete colorbar. Defaults to False. |
False
|
label
|
str
|
Label for the colorbar. Defaults to None. |
None
|
width
|
float
|
The width of the colormap. Defaults to 3.0. |
3.0
|
height
|
float
|
The height of the colormap. Defaults to 0.25. |
0.25
|
orientation
|
str
|
The orientation of the colormap. Defaults to "horizontal". |
'horizontal'
|
vmin
|
float
|
The minimum value range. Defaults to 0. |
0
|
vmax
|
float
|
The maximum value range. Defaults to 1.0. |
1.0
|
axis_off
|
bool
|
Whether to turn axis off. Defaults to False. |
False
|
show_name
|
bool
|
Whether to show the colormap name. Defaults to False. |
False
|
font_size
|
int
|
Font size of the text. Defaults to 12. |
12
|
plot_colormaps(width=8.0, height=0.4, return_fig=False, **kwargs)
¶
Plot all available colormaps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
float
|
Width of the colormap. Defaults to 8.0. |
8.0
|
height
|
float
|
Height of the colormap. Defaults to 0.4. |
0.4
|
return_fig
|
bool
|
Whether to return the figure. Defaults to False. |
False
|