You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@climate.apache.org by go...@apache.org on 2013/08/02 00:32:30 UTC
svn commit: r1509458 -
/incubator/climate/branches/RefactorInput/ocw/plotter.py
Author: goodman
Date: Thu Aug 1 22:32:30 2013
New Revision: 1509458
URL: http://svn.apache.org/r1509458
Log:
CLIMATE-238 - Allow user to enter strings for colormaps
-A set_cmap() helper function was also added to allow the user to change the default colormap.
Modified:
incubator/climate/branches/RefactorInput/ocw/plotter.py
Modified: incubator/climate/branches/RefactorInput/ocw/plotter.py
URL: http://svn.apache.org/viewvc/incubator/climate/branches/RefactorInput/ocw/plotter.py?rev=1509458&r1=1509457&r2=1509458&view=diff
==============================================================================
--- incubator/climate/branches/RefactorInput/ocw/plotter.py (original)
+++ incubator/climate/branches/RefactorInput/ocw/plotter.py Thu Aug 1 22:32:30 2013
@@ -25,6 +25,25 @@ import numpy as np
import numpy.ma as ma
from utils.taylor import TaylorDiagram
+# Set the default colormap to coolwarm
+mpl.rc('image', cmap='coolwarm')
+
+def set_cmap(name):
+ '''
+ Sets the default colormap (eg when setting cmap=None in a function)
+ See: http://matplotlib.org/examples/pylab_examples/show_colormaps.html
+ for a list of possible colormaps.
+ Appending '_r' to a matplotlib colormap name will give you a reversed
+ version of it.
+
+ :param name: The name of the colormap.
+ :type name: str
+ '''
+ # The first line is redundant but it prevents the user from setting
+ # the cmap rc value improperly
+ cmap = plt.get_cmap(name)
+ mpl.rc('image', cmap=cmap.name)
+
def _nice_intervals(data, nlevs):
'''
Purpose::
@@ -126,7 +145,7 @@ def draw_taylor_diagram(results, names,
Draws a Taylor diagram
Input::
- dataset - an Nx2 array containing normalized standard deviations,
+ results - an Nx2 array containing normalized standard deviations,
correlation coefficients, and names of evaluation results
names - list of names for each evaluated dataset
refname - The name of the reference dataset
@@ -410,7 +429,8 @@ def draw_contour_map(dataset, lats, lons
clabel - an optional string specifying the colorbar title
ptitle - an optional string specifying plot title
subtitles - an optional list of strings specifying the title for each subplot
- cmap - an optional matplotlib.LinearSegmentedColormap object denoting the colormap
+ cmap - an string or optional matplotlib.colors.LinearSegmentedColormap instance
+ denoting the colormap
clevs - an optional list of ints or floats specifying contour levels
nlevs - an optional integer specifying the target number of contour levels if
clevs is None
@@ -473,8 +493,7 @@ def draw_contour_map(dataset, lats, lons
clevs = _nice_intervals(dataset, nlevs)
extend = 'both'
- if cmap is None:
- cmap = plt.cm.coolwarm
+ cmap = plt.get_cmap(cmap)
# Create default meridians and parallels. The interval between
# them should be 1, 5, 10, 20, 30, or 40 depending on the size
@@ -558,7 +577,8 @@ def draw_portrait_diagram(results, rowla
clabel - an optional string specifying the colorbar title
ptitle - a string specifying the plot title
subtitles - an optional list of strings specifying the title for each subplot
- cmap - an optional matplotlib.LinearSegmentedColormap object denoting the colormap
+ cmap - an optional string or matplotlib.colors.LinearSegmentedColormap instance
+ denoting the colormap
clevs - an optional list of ints or floats specifying colorbar levels
nlevs - an optional integer specifying the target number of contour levels if
clevs is None
@@ -611,9 +631,7 @@ def draw_portrait_diagram(results, rowla
clevs = _nice_intervals(results, nlevs)
extend = 'both'
- if cmap is None:
- cmap = plt.cm.coolwarm
-
+ cmap = plt.get_cmap(cmap)
norm = mpl.colors.BoundaryNorm(clevs, cmap.N)
# Do the plotting