Skip to content

Full support for string cmaps. #951

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 21, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/matplotlib/cm.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ def get_cmap(name=None, lut=None):
return cmap_d[name]
elif name in datad:
return _generate_cmap(name, lut)
else:
raise ValueError("Colormap %s is not recognized" % name)

raise ValueError("Colormap %s is not recognized" % name)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note the change in scope. This fixes the obtuse message:

>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> plt.imshow(np.arange(12).reshape(3, 4), cmap='hots')
<matplotlib.image.AxesImage object at 0x25265d0>
>>> plt.show()
Traceback (most recent call last):
  File "matplotlib/backends/backend_gtk.py", line 423, in expose_event
    self._render_figure(self._pixmap, w, h)
  File "matplotlib/backends/backend_gtkagg.py", line 75, in _render_figure
    FigureCanvasAgg.draw(self)
  File "matplotlib/backends/backend_agg.py", line 433, in draw
    self.figure.draw(self.renderer)
  File "matplotlib/artist.py", line 55, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "matplotlib/figure.py", line 925, in draw
    func(*args)
  File "matplotlib/artist.py", line 55, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "matplotlib/axes.py", line 1998, in draw
    a.draw(renderer)
  File "matplotlib/artist.py", line 55, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "matplotlib/image.py", line 359, in draw
    im = self.make_image(renderer.get_image_magnification())
  File "matplotlib/image.py", line 579, in make_image
    transformed_viewLim)
  File "matplotlib/image.py", line 202, in _get_unsampled_image
    x = self.to_rgba(self._A, bytes=False)
  File "matplotlib/cm.py", line 241, in to_rgba
    x = self.cmap(x, alpha=alpha, bytes=bytes)
TypeError: 'NoneType' object is not callable


class ScalarMappable:
"""
Expand Down
1 change: 0 additions & 1 deletion lib/matplotlib/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,6 @@ def __init__(self, ax, *args, **kwargs):
if self.origin is not None: assert(self.origin in
['lower', 'upper', 'image'])
if self.extent is not None: assert(len(self.extent) == 4)
if cmap is not None: assert(isinstance(cmap, colors.Colormap))
if self.colors is not None and cmap is not None:
raise ValueError('Either colors or cmap must be None')
if self.origin == 'image': self.origin = mpl.rcParams['image.origin']
Expand Down
12 changes: 8 additions & 4 deletions lib/matplotlib/streamplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
"""
import numpy as np
import matplotlib
import matplotlib.cm as cm
import matplotlib.colors as mcolors
import matplotlib.collections as mcollections
import matplotlib.patches as patches


__all__ = ['streamplot']


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

if use_multicolor_lines:
if norm is None:
norm = matplotlib.colors.normalize(color.min(), color.max())
norm = mcolors.normalize(color.min(), color.max())
if cmap is None:
cmap = matplotlib.cm.get_cmap(matplotlib.rcParams['image.cmap'])
cmap = cm.get_cmap(matplotlib.rcParams['image.cmap'])
else:
cmap = cm.get_cmap(cmap)

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

lc = matplotlib.collections.LineCollection(streamlines, **line_kw)
lc = mcollections.LineCollection(streamlines, **line_kw)
if use_multicolor_lines:
lc.set_array(np.asarray(line_colors))
lc.set_cmap(cmap)
Expand Down