[yt-svn] commit/yt: xarthisius: Merged in ngoldbaum/yt (pull request #2439)
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Tue Dec 6 08:25:36 PST 2016
1 new commit in yt:
https://bitbucket.org/yt_analysis/yt/commits/0207316331dd/
Changeset: 0207316331dd
Branch: yt
User: xarthisius
Date: 2016-12-06 16:25:10+00:00
Summary: Merged in ngoldbaum/yt (pull request #2439)
Add colormaps from cmocean if it's installed
Affected #: 2 files
diff -r 68cdeca5910d377f023631ecf6dbcae1d0794dc3 -r 0207316331dd33da804a692a6c8de656b40173cb doc/source/visualizing/colormaps/index.rst
--- a/doc/source/visualizing/colormaps/index.rst
+++ b/doc/source/visualizing/colormaps/index.rst
@@ -50,6 +50,25 @@
colorblind/printer/grayscale-friendly plots. For more information, visit
`http://colorbrewer2.org <http://colorbrewer2.org>`_.
+.. _cmocean-cmaps:
+
+Colormaps from cmocean
+~~~~~~~~~~~~~~~~~~~~~~
+
+In addition to ``palettable``, yt will also import colormaps defined in the
+`cmocean <http://matplotlib.org/cmocean>`_ package. These colormaps are
+`perceptually uniform <http://bids.github.io/colormap/>`_ and were originally
+designed for oceanography applications, but can be used for any kind of plots.
+
+Since ``cmocean`` is not installed as a dependency of yt by default, it must be
+installed separately to access the ``cmocean`` colormaps with yt. The easiest
+way to install ``cmocean`` is via ``pip``: ``pip install cmocean``. To access
+the colormaps in yt, simply specify the name of the ``cmocean`` colormap in any
+context where you would specify a colormap. One caveat is the ``cmocean``
+colormap ``algae``. Since yt already defines a colormap named ``algae``, the
+``cmocean`` version of ``algae`` must be specified with the name
+``algae_cmocean``.
+
.. _custom-colormaps:
Making and Viewing Custom Colormaps
diff -r 68cdeca5910d377f023631ecf6dbcae1d0794dc3 -r 0207316331dd33da804a692a6c8de656b40173cb yt/visualization/color_maps.py
--- a/yt/visualization/color_maps.py
+++ b/yt/visualization/color_maps.py
@@ -17,6 +17,11 @@
from . import _colormap_data as _cm
from yt.extern.six import string_types
+try:
+ import cmocean
+except ImportError:
+ cmocean = None
+
def is_colormap(cmap):
return isinstance(cmap,cc.Colormap)
@@ -152,6 +157,22 @@
add_cmap("cubehelix", _cubehelix_data)
+# Add colormaps from cmocean, if it's installed
+if cmocean is not None:
+ for cmname in cmocean.cm.cmapnames:
+ cm = getattr(cmocean.cm, cmname)
+ # cmocean has a colormap named 'algae', so let's avoid overwriting
+ # yt's algae or any other colormap we've already added
+ if cmname in yt_colormaps:
+ cmname = cmname + '_cmocean'
+ yt_colormaps[cmname] = cm
+ try:
+ mcm.register_cmap(cmname, yt_colormaps[cmname])
+ except AttributeError:
+ # for old versions of matplotlib this won't work, so we avoid
+ # erroring out but don't worry about registering with matplotlib
+ pass
+
# Add colormaps in _colormap_data.py that weren't defined here
_vs = np.linspace(0,1,256)
for k,v in list(_cm.color_map_luts.items()):
Repository URL: https://bitbucket.org/yt_analysis/yt/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the yt-svn
mailing list