| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 1d1d8ba commit cc977dc
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -146,6 +146,11 @@ def register(self, cmap, *, name=None, force=False): | |||
| 146 | 146 | "that was already in the registry.") | |
| 147 | 147 | ||
| 148 | 148 | self._cmaps[name] = cmap.copy() | |
| 149 | + # Someone may set the extremes of a builtin colormap and want to register it | ||
| 150 | + # with a different name for future lookups. The object would still have the | ||
| 151 | + # builtin name, so we should update it to the registered name | ||
| 152 | + if self._cmaps[name].name != name: | ||
| 153 | + self._cmaps[name].name = name | ||
| 149 | 154 | ||
| 150 | 155 | def unregister(self, name): | |
| 151 | 156 | """ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -774,7 +774,7 @@ def __copy__(self): | |||
| 774 | 774 | return cmapobject | |
| 775 | 775 | ||
| 776 | 776 | def __eq__(self, other): | |
| 777 | - if (not isinstance(other, Colormap) or self.name != other.name or | ||
| 777 | + if (not isinstance(other, Colormap) or | ||
| 778 | 778 | self.colorbar_extend != other.colorbar_extend): | |
| 779 | 779 | return False | |
| 780 | 780 | # To compare lookup tables the Colormaps have to be initialized | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -195,10 +195,10 @@ def test_colormap_equals(): | |||
| 195 | 195 | # Make sure we can compare different sizes without failure | |
| 196 | 196 | cm_copy._lut = cm_copy._lut[:10, :] | |
| 197 | 197 | assert cm_copy != cmap | |
| 198 | - # Test different names are not equal | ||
| 198 | + # Test different names are equal if the lookup table is the same | ||
| 199 | 199 | cm_copy = cmap.copy() | |
| 200 | 200 | cm_copy.name = "Test" | |
| 201 | - assert cm_copy != cmap | ||
| 201 | + assert cm_copy == cmap | ||
| 202 | 202 | # Test colorbar extends | |
| 203 | 203 | cm_copy = cmap.copy() | |
| 204 | 204 | cm_copy.colorbar_extend = not cmap.colorbar_extend | |
@@ -1649,3 +1649,15 @@ def test_cm_set_cmap_error(): | |||
| 1649 | 1649 | bad_cmap = 'AardvarksAreAwkward' | |
| 1650 | 1650 | with pytest.raises(ValueError, match=bad_cmap): | |
| 1651 | 1651 | sm.set_cmap(bad_cmap) | |
| 1652 | + | ||
| 1653 | + | ||
| 1654 | + def test_set_cmap_mismatched_name(): | ||
| 1655 | + cmap = matplotlib.colormaps["viridis"].with_extremes(over='r') | ||
| 1656 | + # register it with different names | ||
| 1657 | + cmap.name = "test-cmap" | ||
| 1658 | + matplotlib.colormaps.register(name='wrong-cmap', cmap=cmap) | ||
| 1659 | + | ||
| 1660 | + plt.set_cmap("wrong-cmap") | ||
| 1661 | + cmap_returned = plt.get_cmap("wrong-cmap") | ||
| 1662 | + assert cmap_returned == cmap | ||
| 1663 | + assert cmap_returned.name == "wrong-cmap" | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments