Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2b4ab26

Browse files
committed
Merge pull request matplotlib#951 from pelson/cmap_strings
Contour and streamplot support for cmaps passed by name.
2 parents a2d44d5 + 715fb43 commit 2b4ab26

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

‎lib/matplotlib/cm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ def get_cmap(name=None, lut=None):
151151
return cmap_d[name]
152152
elif name in datad:
153153
return _generate_cmap(name, lut)
154-
else:
155-
raise ValueError("Colormap %s is not recognized" % name)
154+
155+
raise ValueError("Colormap %s is not recognized" % name)
156156

157157
class ScalarMappable:
158158
"""

‎lib/matplotlib/contour.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,6 @@ def __init__(self, ax, *args, **kwargs):
766766
if self.origin is not None: assert(self.origin in
767767
['lower', 'upper', 'image'])
768768
if self.extent is not None: assert(len(self.extent) == 4)
769-
if cmap is not None: assert(isinstance(cmap, colors.Colormap))
770769
if self.colors is not None and cmap is not None:
771770
raise ValueError('Either colors or cmap must be None')
772771
if self.origin == 'image': self.origin = mpl.rcParams['image.origin']

‎lib/matplotlib/streamplot.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
"""
55
import numpy as np
66
import matplotlib
7+
import matplotlib.cm as cm
8+
import matplotlib.colors as mcolors
9+
import matplotlib.collections as mcollections
710
import matplotlib.patches as patches
811

9-
1012
__all__ = ['streamplot']
1113

1214

@@ -103,9 +105,11 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
103105

104106
if use_multicolor_lines:
105107
if norm is None:
106-
norm = matplotlib.colors.normalize(color.min(), color.max())
108+
norm = mcolors.normalize(color.min(), color.max())
107109
if cmap is None:
108-
cmap = matplotlib.cm.get_cmap(matplotlib.rcParams['image.cmap'])
110+
cmap = cm.get_cmap(matplotlib.rcParams['image.cmap'])
111+
else:
112+
cmap = cm.get_cmap(cmap)
109113

110114
streamlines = []
111115
for t in trajectories:
@@ -137,7 +141,7 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
137141
p = patches.FancyArrowPatch(arrow_tail, arrow_head, **arrow_kw)
138142
axes.add_patch(p)
139143

140-
lc = matplotlib.collections.LineCollection(streamlines, **line_kw)
144+
lc = mcollections.LineCollection(streamlines, **line_kw)
141145
if use_multicolor_lines:
142146
lc.set_array(np.asarray(line_colors))
143147
lc.set_cmap(cmap)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /