| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -561,7 +561,7 @@ def _warn_if_global_cmap_modified(cmap): | |||
| 561 | 561 | "colormap. In future versions, you will not be able to " | |
| 562 | 562 | "modify a registered colormap in-place. To remove this " | |
| 563 | 563 | "warning, you can make a copy of the colormap first. " | |
| 564 | - f'cmap = copy.copy(mpl.cm.get_cmap("{cmap.name}"))' | ||
| 564 | + f'cmap = mpl.cm.get_cmap("{cmap.name}").copy()' | ||
| 565 | 565 | ) | |
| 566 | 566 | ||
| 567 | 567 | ||
@@ -845,6 +845,12 @@ def color_block(color): | |||
| 845 | 845 | f'over {color_block(self.get_over())}' | |
| 846 | 846 | '</div>') | |
| 847 | 847 | ||
| 848 | + def copy(self): | ||
| 849 | + """ | ||
| 850 | + Return a copy of the colormap. | ||
| 851 | + """ | ||
| 852 | + return self.__copy__() | ||
| 853 | + | ||
| 848 | 854 | ||
| 849 | 855 | class LinearSegmentedColormap(Colormap): | |
| 850 | 856 | """ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -150,6 +150,16 @@ def test_colormap_copy(): | |||
| 150 | 150 | with np.errstate(invalid='ignore'): | |
| 151 | 151 | ret2 = copied_cmap([-1, 0, .5, 1, np.nan, np.inf]) | |
| 152 | 152 | assert_array_equal(ret1, ret2) | |
| 153 | + # again with the .copy method: | ||
| 154 | + cmap = plt.cm.Reds | ||
| 155 | + copied_cmap = cmap.copy() | ||
| 156 | + with np.errstate(invalid='ignore'): | ||
| 157 | + ret1 = copied_cmap([-1, 0, .5, 1, np.nan, np.inf]) | ||
| 158 | + cmap2 = copy.copy(copied_cmap) | ||
| 159 | + cmap2.set_bad('g') | ||
| 160 | + with np.errstate(invalid='ignore'): | ||
| 161 | + ret2 = copied_cmap([-1, 0, .5, 1, np.nan, np.inf]) | ||
| 162 | + assert_array_equal(ret1, ret2) | ||
| 153 | 163 | ||
| 154 | 164 | ||
| 155 | 165 | def test_colormap_endian(): | |
| Back | FazBrowse Home | New Git URL |
0 commit comments