Skip to content

Commit

Permalink
Merge pull request #967 from astrofrog/fix-colormap-saving
Browse files Browse the repository at this point in the history
Fix saving of Matplotlib colormaps to session files
  • Loading branch information
astrofrog committed May 3, 2016
1 parent 69ca700 commit 2dde1a7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ v0.7.3 (unreleased)
* Remove the scrollbars added in v0.7.1 since they cause issues on certain
systems. [#953]

* Fix saving of Matplotlib colormaps to session files. [#967]

* Remove icons for actions that appear in contextual menus, since these
appear too large due to a Qt bug. [#911]

Expand Down
10 changes: 10 additions & 0 deletions glue/core/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ def load(rec, context)
from inspect import isgeneratorfunction

import numpy as np
from matplotlib.colors import Colormap
from matplotlib import cm

from glue.external import six
from glue import core
Expand Down Expand Up @@ -808,3 +810,11 @@ def _save_numpy(obj, context):
np.save(f, obj)
data = b64encode(f.getvalue()).decode('ascii')
return dict(data=data)

@saver(Colormap)
def _save_cmap(cmap, context):
return {'cmap':cmap.name}

@loader(Colormap)
def _load_cmap(rec, context):
return cm.get_cmap(rec['cmap'])
6 changes: 6 additions & 0 deletions glue/core/tests/test_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ def test_polygonal_roi():
assert r2.vx == [0, 0, 1]
assert r2.vy == [0, 1, 0]


def test_matplotlib_cmap():
from matplotlib import cm
assert clone(cm.gist_heat) is cm.gist_heat


class DummyClass(object):
pass

Expand Down

0 comments on commit 2dde1a7

Please sign in to comment.