-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add colormap thumbnail script * Add colormaps doc * Coerce name to lower case * Apply black on data * Escape spaces in markdown * Replace space with underscore * Add docstring * rename geographic colormaps * add refs for custom colormaps * fix link * format Co-authored-by: Kyle Barron <[email protected]>
- Loading branch information
1 parent
3f5d94a
commit fb7da01
Showing
11 changed files
with
223 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Colormaps | ||
|
||
Rio-tiler includes many colormaps, some derived from Matplotlib and some custom | ||
ones that are commonly-used with raster data. | ||
|
||
You can load a colormap with `rio_tiler.colormap.get_colormap`, and then pass it | ||
to `rio_tiler.utils.render`: | ||
|
||
```py | ||
from rio_tiler.colormap import get_colormap | ||
from rio_tiler.utils import render | ||
|
||
colormap = get_colormap('cfastie') | ||
render(tile, mask, colormap=colormap) | ||
``` | ||
|
||
![](img/custom.png) | ||
![](img/perceptually_uniform_sequential.png) | ||
![](img/sequential.png) | ||
![](img/sequential_(2).png) | ||
![](img/diverging.png) | ||
![](img/cyclic.png) | ||
![](img/qualitative.png) | ||
![](img/miscellaneous.png) | ||
|
||
### Refs | ||
- Matplotlib: https://matplotlib.org/3.1.0/tutorials/colors/colormaps.html | ||
- cfastie: http://publiclab.org/notes/cfastie/08-26-2014/new-ndvi-colormap | ||
- rplumbo: https://github.com/cogeotiff/rio-tiler/pull/90 | ||
- schwarzwald: http://soliton.vm.bytemark.co.uk/pub/cpt-city/wkp/schwarzwald/tn/wiki-schwarzwald-cont.png.index.html | ||
|
||
### Update images for new colormaps | ||
|
||
To regenerate these images for new colormaps, update the list of colormaps at | ||
the top of `scripts/colormap_thumb.py` and then run | ||
|
||
```bash | ||
python scripts/colormap_thumb.py | ||
``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
""" | ||
colormap_thumb.py: Create colormap thumbnails for documentation | ||
This file is derived from the matplotlib documentation. | ||
https://matplotlib.org/tutorials/colors/colormaps.html | ||
""" | ||
from pathlib import Path | ||
|
||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
from matplotlib.colors import ListedColormap | ||
from rio_tiler.colormap import get_colormap, make_lut | ||
|
||
|
||
cmaps = [ | ||
("Custom", ["cfastie", "rplumbo", "schwarzwald"]), | ||
( | ||
"Perceptually Uniform Sequential", | ||
["viridis", "plasma", "inferno", "magma", "cividis"], | ||
), | ||
( | ||
"Sequential", | ||
[ | ||
"Greys", | ||
"Purples", | ||
"Blues", | ||
"Greens", | ||
"Oranges", | ||
"Reds", | ||
"YlOrBr", | ||
"YlOrRd", | ||
"OrRd", | ||
"PuRd", | ||
"RdPu", | ||
"BuPu", | ||
"GnBu", | ||
"PuBu", | ||
"YlGnBu", | ||
"PuBuGn", | ||
"BuGn", | ||
"YlGn", | ||
], | ||
), | ||
( | ||
"Sequential (2)", | ||
[ | ||
"binary", | ||
"gist_yarg", | ||
"gist_gray", | ||
"gray", | ||
"bone", | ||
"pink", | ||
"spring", | ||
"summer", | ||
"autumn", | ||
"winter", | ||
"cool", | ||
"Wistia", | ||
"hot", | ||
"afmhot", | ||
"gist_heat", | ||
"copper", | ||
], | ||
), | ||
( | ||
"Diverging", | ||
[ | ||
"PiYG", | ||
"PRGn", | ||
"BrBG", | ||
"PuOr", | ||
"RdGy", | ||
"RdBu", | ||
"RdYlBu", | ||
"RdYlGn", | ||
"Spectral", | ||
"coolwarm", | ||
"bwr", | ||
"seismic", | ||
], | ||
), | ||
("Cyclic", ["twilight", "twilight_shifted", "hsv"]), | ||
( | ||
"Qualitative", | ||
[ | ||
"Pastel1", | ||
"Pastel2", | ||
"Paired", | ||
"Accent", | ||
"Dark2", | ||
"Set1", | ||
"Set2", | ||
"Set3", | ||
"tab10", | ||
"tab20", | ||
"tab20b", | ||
"tab20c", | ||
], | ||
), | ||
( | ||
"Miscellaneous", | ||
[ | ||
"flag", | ||
"prism", | ||
"ocean", | ||
"gist_earth", | ||
"terrain", | ||
"gist_stern", | ||
"gnuplot", | ||
"gnuplot2", | ||
"CMRmap", | ||
"cubehelix", | ||
"brg", | ||
"gist_rainbow", | ||
"rainbow", | ||
"jet", | ||
"nipy_spectral", | ||
"gist_ncar", | ||
], | ||
), | ||
] | ||
|
||
|
||
gradient = np.linspace(0, 1, 256) | ||
gradient = np.vstack((gradient, gradient)) | ||
|
||
|
||
def make_colormap(name): | ||
"""Use rio-tiler colormap to create matplotlib colormap | ||
""" | ||
cmap = make_lut(get_colormap(name)) | ||
# rescale to 0-1 | ||
return ListedColormap(cmap / 255, name=name) | ||
|
||
|
||
def plot_color_gradients(cmap_category, cmap_list): | ||
"""Make | ||
""" | ||
# Create figure and adjust figure height to number of colormaps | ||
nrows = len(cmap_list) | ||
figh = 0.35 + 0.15 + (nrows + (nrows - 1) * 0.1) * 0.22 | ||
fig, axes = plt.subplots(nrows=nrows, figsize=(6.4, figh)) | ||
fig.subplots_adjust(top=1 - 0.35 / figh, bottom=0.15 / figh, left=0.2, right=0.99) | ||
|
||
axes[0].set_title(cmap_category + " colormaps", fontsize=14) | ||
|
||
for ax, name in zip(axes, cmap_list): | ||
ax.imshow(gradient, aspect="auto", cmap=make_colormap(name)) | ||
ax.text( | ||
-0.01, | ||
0.5, | ||
name, | ||
va="center", | ||
ha="right", | ||
fontsize=10, | ||
transform=ax.transAxes, | ||
) | ||
|
||
# Turn off *all* ticks & spines, not just the ones with colormaps. | ||
for ax in axes: | ||
ax.set_axis_off() | ||
|
||
return fig | ||
|
||
|
||
def main(): | ||
"""Create thumbnails""" | ||
for cmap_category, cmap_list in cmaps: | ||
plot_color_gradients(cmap_category, cmap_list) | ||
|
||
# Export fig | ||
out_path = ( | ||
Path(__file__).parents[0] | ||
/ ".." | ||
/ "img" | ||
/ (cmap_category.replace(" ", "_").lower() + ".png") | ||
) | ||
out_path.parents[0].mkdir(exist_ok=True) | ||
plt.savefig(out_path, dpi=200) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters