Skip to content

Commit

Permalink
Only register matplotlib cmaps once (#36)
Browse files Browse the repository at this point in the history
* MNT: remove duplicate registration of dimgray

Both dimgray and dimgray_r are registering in the `mpl_cm` and do not
need to be registered again.

* MNT: remove the rest of the duplicate registration

All colormaps were double registered.

* TST: all colormaps are accessible via mpl.cm.get_cmap

* Making change to __init__ writer

* Use python 3.7

* Adding py36, we'll test that on windows
  • Loading branch information
jsignell authored Aug 27, 2019
1 parent f66d021 commit e0ff3c7
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 62 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ env:
- CHANS_REL="-c pyviz"
- LABELS_DEV="--label dev"
- LABELS_REL="--label dev --label main"
- PYENV_VERSION=3.6
- PKG_TEST_PYTHON="--test-python=py36 --test-python=py27"
- PYENV_VERSION=3.7
- PKG_TEST_PYTHON="--test-python=py37 --test-python=py27"

stages:
- test
Expand Down
5 changes: 3 additions & 2 deletions assets/CET_to_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,9 @@ def create_alias(alias, base, output, is_name=True):
if is_name:
output.write("cm_n['{0}'] = mpl_cm('{0}',{1})\n".format(alias,base))
output.write("cm_n['{0}_r'] = mpl_cm('{0}_r',list(reversed({1})))\n".format(alias,base))
output.write("register_cmap('cet_{0}',m_{1})\n".format(alias,base))
output.write("register_cmap('cet_{0}_r',m_{1}_r)\n".format(alias,base))
else:
output.write("register_cmap('cet_{0}',m_{1})\n".format(alias,base))
output.write("register_cmap('cet_{0}_r',m_{1}_r)\n".format(alias,base))

cmaps = []
with open(output_file, "w") as output:
Expand Down
58 changes: 1 addition & 57 deletions colorcet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,8 +670,6 @@ def all_original_names(group=None, not_group=None, only_aliased=False, only_CET=
cm['dimgray_r'] = m_linear_grey_10_95_c0_r
cm_n['dimgray'] = mpl_cm('dimgray',linear_grey_10_95_c0)
cm_n['dimgray_r'] = mpl_cm('dimgray_r',list(reversed(linear_grey_10_95_c0)))
register_cmap('cet_dimgray',m_linear_grey_10_95_c0)
register_cmap('cet_dimgray_r',m_linear_grey_10_95_c0_r)
CET_L2 = b_linear_grey_10_95_c0
m_CET_L2 = m_linear_grey_10_95_c0
m_CET_L2_r = m_linear_grey_10_95_c0_r
Expand Down Expand Up @@ -1227,8 +1225,6 @@ def all_original_names(group=None, not_group=None, only_aliased=False, only_CET=
cm['bky_r'] = m_diverging_bky_60_10_c30_r
cm_n['bky'] = mpl_cm('bky',diverging_bky_60_10_c30)
cm_n['bky_r'] = mpl_cm('bky_r',list(reversed(diverging_bky_60_10_c30)))
register_cmap('cet_bky',m_diverging_bky_60_10_c30)
register_cmap('cet_bky_r',m_diverging_bky_60_10_c30_r)
CET_D6 = b_diverging_bky_60_10_c30
m_CET_D6 = m_diverging_bky_60_10_c30
m_CET_D6_r = m_diverging_bky_60_10_c30_r
Expand Down Expand Up @@ -1511,8 +1507,6 @@ def all_original_names(group=None, not_group=None, only_aliased=False, only_CET=
cm['coolwarm_r'] = m_diverging_bwr_40_95_c42_r
cm_n['coolwarm'] = mpl_cm('coolwarm',diverging_bwr_40_95_c42)
cm_n['coolwarm_r'] = mpl_cm('coolwarm_r',list(reversed(diverging_bwr_40_95_c42)))
register_cmap('cet_coolwarm',m_diverging_bwr_40_95_c42)
register_cmap('cet_coolwarm_r',m_diverging_bwr_40_95_c42_r)
CET_D1 = b_diverging_bwr_40_95_c42
m_CET_D1 = m_diverging_bwr_40_95_c42
m_CET_D1_r = m_diverging_bwr_40_95_c42_r
Expand Down Expand Up @@ -2068,9 +2062,6 @@ def all_original_names(group=None, not_group=None, only_aliased=False, only_CET=
cm['kbc_r'] = m_linear_blue_5_95_c73_r
cm_n['kbc'] = mpl_cm('kbc',linear_blue_5_95_c73)
cm_n['kbc_r'] = mpl_cm('kbc_r',list(reversed(linear_blue_5_95_c73)))
register_cmap('cet_kbc',m_linear_blue_5_95_c73)
register_cmap('cet_kbc_r',m_linear_blue_5_95_c73_r)




Expand Down Expand Up @@ -2609,8 +2600,6 @@ def all_original_names(group=None, not_group=None, only_aliased=False, only_CET=
cm['gwv_r'] = m_diverging_gwv_55_95_c39_r
cm_n['gwv'] = mpl_cm('gwv',diverging_gwv_55_95_c39)
cm_n['gwv_r'] = mpl_cm('gwv_r',list(reversed(diverging_gwv_55_95_c39)))
register_cmap('cet_gwv',m_diverging_gwv_55_95_c39)
register_cmap('cet_gwv_r',m_diverging_gwv_55_95_c39_r)
CET_D2 = b_diverging_gwv_55_95_c39
m_CET_D2 = m_diverging_gwv_55_95_c39
m_CET_D2_r = m_diverging_gwv_55_95_c39_r
Expand Down Expand Up @@ -3158,8 +3147,6 @@ def all_original_names(group=None, not_group=None, only_aliased=False, only_CET=
cm['kg_r'] = m_linear_ternary_green_0_46_c42_r
cm_n['kg'] = mpl_cm('kg',linear_ternary_green_0_46_c42)
cm_n['kg_r'] = mpl_cm('kg_r',list(reversed(linear_ternary_green_0_46_c42)))
register_cmap('cet_kg',m_linear_ternary_green_0_46_c42)
register_cmap('cet_kg_r',m_linear_ternary_green_0_46_c42_r)
CET_L14 = b_linear_ternary_green_0_46_c42
m_CET_L14 = m_linear_ternary_green_0_46_c42
m_CET_L14_r = m_linear_ternary_green_0_46_c42_r
Expand Down Expand Up @@ -3980,8 +3967,6 @@ def all_original_names(group=None, not_group=None, only_aliased=False, only_CET=
cm['colorwheel_r'] = m_cyclic_mygbm_30_95_c78_s25_r
cm_n['colorwheel'] = mpl_cm('colorwheel',cyclic_mygbm_30_95_c78_s25)
cm_n['colorwheel_r'] = mpl_cm('colorwheel_r',list(reversed(cyclic_mygbm_30_95_c78_s25)))
register_cmap('cet_colorwheel',m_cyclic_mygbm_30_95_c78_s25)
register_cmap('cet_colorwheel_r',m_cyclic_mygbm_30_95_c78_s25_r)
CET_C2s = b_cyclic_mygbm_30_95_c78_s25
m_CET_C2s = m_cyclic_mygbm_30_95_c78_s25
m_CET_C2s_r = m_cyclic_mygbm_30_95_c78_s25_r
Expand Down Expand Up @@ -4537,8 +4522,6 @@ def all_original_names(group=None, not_group=None, only_aliased=False, only_CET=
cm['bgyw_r'] = m_linear_bgyw_15_100_c68_r
cm_n['bgyw'] = mpl_cm('bgyw',linear_bgyw_15_100_c68)
cm_n['bgyw_r'] = mpl_cm('bgyw_r',list(reversed(linear_bgyw_15_100_c68)))
register_cmap('cet_bgyw',m_linear_bgyw_15_100_c68)
register_cmap('cet_bgyw_r',m_linear_bgyw_15_100_c68_r)



Expand Down Expand Up @@ -5905,8 +5888,6 @@ def all_original_names(group=None, not_group=None, only_aliased=False, only_CET=
cm['gray_r'] = m_linear_grey_0_100_c0_r
cm_n['gray'] = mpl_cm('gray',linear_grey_0_100_c0)
cm_n['gray_r'] = mpl_cm('gray_r',list(reversed(linear_grey_0_100_c0)))
register_cmap('cet_gray',m_linear_grey_0_100_c0)
register_cmap('cet_gray_r',m_linear_grey_0_100_c0_r)
CET_L1 = b_linear_grey_0_100_c0
m_CET_L1 = m_linear_grey_0_100_c0
m_CET_L1_r = m_linear_grey_0_100_c0_r
Expand Down Expand Up @@ -6727,8 +6708,6 @@ def all_original_names(group=None, not_group=None, only_aliased=False, only_CET=
cm['rainbow_r'] = m_rainbow_bgyr_35_85_c73_r
cm_n['rainbow'] = mpl_cm('rainbow',rainbow_bgyr_35_85_c73)
cm_n['rainbow_r'] = mpl_cm('rainbow_r',list(reversed(rainbow_bgyr_35_85_c73)))
register_cmap('cet_rainbow',m_rainbow_bgyr_35_85_c73)
register_cmap('cet_rainbow_r',m_rainbow_bgyr_35_85_c73_r)



Expand Down Expand Up @@ -7541,8 +7520,6 @@ def all_original_names(group=None, not_group=None, only_aliased=False, only_CET=
cm['blues_r'] = m_linear_blue_95_50_c20_r
cm_n['blues'] = mpl_cm('blues',linear_blue_95_50_c20)
cm_n['blues_r'] = mpl_cm('blues_r',list(reversed(linear_blue_95_50_c20)))
register_cmap('cet_blues',m_linear_blue_95_50_c20)
register_cmap('cet_blues_r',m_linear_blue_95_50_c20_r)
CET_L12 = b_linear_blue_95_50_c20
m_CET_L12 = m_linear_blue_95_50_c20
m_CET_L12_r = m_linear_blue_95_50_c20_r
Expand Down Expand Up @@ -7825,8 +7802,6 @@ def all_original_names(group=None, not_group=None, only_aliased=False, only_CET=
cm['kr_r'] = m_linear_ternary_red_0_50_c52_r
cm_n['kr'] = mpl_cm('kr',linear_ternary_red_0_50_c52)
cm_n['kr_r'] = mpl_cm('kr_r',list(reversed(linear_ternary_red_0_50_c52)))
register_cmap('cet_kr',m_linear_ternary_red_0_50_c52)
register_cmap('cet_kr_r',m_linear_ternary_red_0_50_c52_r)
CET_L13 = b_linear_ternary_red_0_50_c52
m_CET_L13 = m_linear_ternary_red_0_50_c52
m_CET_L13_r = m_linear_ternary_red_0_50_c52_r
Expand Down Expand Up @@ -8912,8 +8887,6 @@ def all_original_names(group=None, not_group=None, only_aliased=False, only_CET=
cm['fire_r'] = m_linear_kryw_0_100_c71_r
cm_n['fire'] = mpl_cm('fire',linear_kryw_0_100_c71)
cm_n['fire_r'] = mpl_cm('fire_r',list(reversed(linear_kryw_0_100_c71)))
register_cmap('cet_fire',m_linear_kryw_0_100_c71)
register_cmap('cet_fire_r',m_linear_kryw_0_100_c71_r)
CET_L3 = b_linear_kryw_0_100_c71
m_CET_L3 = m_linear_kryw_0_100_c71
m_CET_L3_r = m_linear_kryw_0_100_c71_r
Expand Down Expand Up @@ -9196,8 +9169,6 @@ def all_original_names(group=None, not_group=None, only_aliased=False, only_CET=
cm['bkr_r'] = m_diverging_bkr_55_10_c35_r
cm_n['bkr'] = mpl_cm('bkr',diverging_bkr_55_10_c35)
cm_n['bkr_r'] = mpl_cm('bkr_r',list(reversed(diverging_bkr_55_10_c35)))
register_cmap('cet_bkr',m_diverging_bkr_55_10_c35)
register_cmap('cet_bkr_r',m_diverging_bkr_55_10_c35_r)
CET_D4 = b_diverging_bkr_55_10_c35
m_CET_D4 = m_diverging_bkr_55_10_c35
m_CET_D4_r = m_diverging_bkr_55_10_c35_r
Expand Down Expand Up @@ -9480,8 +9451,7 @@ def all_original_names(group=None, not_group=None, only_aliased=False, only_CET=
cm['kgy_r'] = m_linear_green_5_95_c69_r
cm_n['kgy'] = mpl_cm('kgy',linear_green_5_95_c69)
cm_n['kgy_r'] = mpl_cm('kgy_r',list(reversed(linear_green_5_95_c69)))
register_cmap('cet_kgy',m_linear_green_5_95_c69)
register_cmap('cet_kgy_r',m_linear_green_5_95_c69_r)




Expand Down Expand Up @@ -9756,8 +9726,6 @@ def all_original_names(group=None, not_group=None, only_aliased=False, only_CET=
cm['bmw_r'] = m_linear_bmw_5_95_c89_r
cm_n['bmw'] = mpl_cm('bmw',linear_bmw_5_95_c89)
cm_n['bmw_r'] = mpl_cm('bmw_r',list(reversed(linear_bmw_5_95_c89)))
register_cmap('cet_bmw',m_linear_bmw_5_95_c89)
register_cmap('cet_bmw_r',m_linear_bmw_5_95_c89_r)



Expand Down Expand Up @@ -10305,8 +10273,6 @@ def all_original_names(group=None, not_group=None, only_aliased=False, only_CET=
cm['isolum_r'] = m_isoluminant_cgo_80_c38_r
cm_n['isolum'] = mpl_cm('isolum',isoluminant_cgo_80_c38)
cm_n['isolum_r'] = mpl_cm('isolum_r',list(reversed(isoluminant_cgo_80_c38)))
register_cmap('cet_isolum',m_isoluminant_cgo_80_c38)
register_cmap('cet_isolum_r',m_isoluminant_cgo_80_c38_r)
CET_I2 = b_isoluminant_cgo_80_c38
m_CET_I2 = m_isoluminant_cgo_80_c38
m_CET_I2_r = m_isoluminant_cgo_80_c38_r
Expand Down Expand Up @@ -11408,8 +11374,6 @@ def all_original_names(group=None, not_group=None, only_aliased=False, only_CET=
cm['bmy_r'] = m_linear_bmy_10_95_c78_r
cm_n['bmy'] = mpl_cm('bmy',linear_bmy_10_95_c78)
cm_n['bmy_r'] = mpl_cm('bmy_r',list(reversed(linear_bmy_10_95_c78)))
register_cmap('cet_bmy',m_linear_bmy_10_95_c78)
register_cmap('cet_bmy_r',m_linear_bmy_10_95_c78_r)



Expand Down Expand Up @@ -11957,8 +11921,6 @@ def all_original_names(group=None, not_group=None, only_aliased=False, only_CET=
cm['kb_r'] = m_linear_ternary_blue_0_44_c57_r
cm_n['kb'] = mpl_cm('kb',linear_ternary_blue_0_44_c57)
cm_n['kb_r'] = mpl_cm('kb_r',list(reversed(linear_ternary_blue_0_44_c57)))
register_cmap('cet_kb',m_linear_ternary_blue_0_44_c57)
register_cmap('cet_kb_r',m_linear_ternary_blue_0_44_c57_r)
CET_L15 = b_linear_ternary_blue_0_44_c57
m_CET_L15 = m_linear_ternary_blue_0_44_c57
m_CET_L15_r = m_linear_ternary_blue_0_44_c57_r
Expand Down Expand Up @@ -13060,8 +13022,6 @@ def all_original_names(group=None, not_group=None, only_aliased=False, only_CET=
cm['bgy_r'] = m_linear_bgy_10_95_c74_r
cm_n['bgy'] = mpl_cm('bgy',linear_bgy_10_95_c74)
cm_n['bgy_r'] = mpl_cm('bgy_r',list(reversed(linear_bgy_10_95_c74)))
register_cmap('cet_bgy',m_linear_bgy_10_95_c74)
register_cmap('cet_bgy_r',m_linear_bgy_10_95_c74_r)



Expand Down Expand Up @@ -14147,8 +14107,6 @@ def all_original_names(group=None, not_group=None, only_aliased=False, only_CET=
cm['bjy_r'] = m_diverging_linear_bjy_30_90_c45_r
cm_n['bjy'] = mpl_cm('bjy',diverging_linear_bjy_30_90_c45)
cm_n['bjy_r'] = mpl_cm('bjy_r',list(reversed(diverging_linear_bjy_30_90_c45)))
register_cmap('cet_bjy',m_diverging_linear_bjy_30_90_c45)
register_cmap('cet_bjy_r',m_diverging_linear_bjy_30_90_c45_r)
CET_D7 = b_diverging_linear_bjy_30_90_c45
m_CET_D7 = m_diverging_linear_bjy_30_90_c45
m_CET_D7_r = m_diverging_linear_bjy_30_90_c45_r
Expand Down Expand Up @@ -16888,8 +16846,6 @@ def all_original_names(group=None, not_group=None, only_aliased=False, only_CET=
cm['bwy_r'] = m_diverging_protanopic_deuteranopic_bwy_60_95_c32_r
cm_n['bwy'] = mpl_cm('bwy',diverging_protanopic_deuteranopic_bwy_60_95_c32)
cm_n['bwy_r'] = mpl_cm('bwy_r',list(reversed(diverging_protanopic_deuteranopic_bwy_60_95_c32)))
register_cmap('cet_bwy',m_diverging_protanopic_deuteranopic_bwy_60_95_c32)
register_cmap('cet_bwy_r',m_diverging_protanopic_deuteranopic_bwy_60_95_c32_r)
CET_CBD1 = b_diverging_protanopic_deuteranopic_bwy_60_95_c32
m_CET_CBD1 = m_diverging_protanopic_deuteranopic_bwy_60_95_c32
m_CET_CBD1_r = m_diverging_protanopic_deuteranopic_bwy_60_95_c32_r
Expand Down Expand Up @@ -17172,8 +17128,6 @@ def all_original_names(group=None, not_group=None, only_aliased=False, only_CET=
cm['cwr_r'] = m_diverging_tritanopic_cwr_75_98_c20_r
cm_n['cwr'] = mpl_cm('cwr',diverging_tritanopic_cwr_75_98_c20)
cm_n['cwr_r'] = mpl_cm('cwr_r',list(reversed(diverging_tritanopic_cwr_75_98_c20)))
register_cmap('cet_cwr',m_diverging_tritanopic_cwr_75_98_c20)
register_cmap('cet_cwr_r',m_diverging_tritanopic_cwr_75_98_c20_r)
CET_CBTD1 = b_diverging_tritanopic_cwr_75_98_c20
m_CET_CBTD1 = m_diverging_tritanopic_cwr_75_98_c20
m_CET_CBTD1_r = m_diverging_tritanopic_cwr_75_98_c20_r
Expand Down Expand Up @@ -20178,8 +20132,6 @@ def all_original_names(group=None, not_group=None, only_aliased=False, only_CET=
cm['glasbey_light_r'] = m_glasbey_bw_minc_20_minl_30_r
cm_n['glasbey_light'] = mpl_cm('glasbey_light',glasbey_bw_minc_20_minl_30)
cm_n['glasbey_light_r'] = mpl_cm('glasbey_light_r',list(reversed(glasbey_bw_minc_20_minl_30)))
register_cmap('cet_glasbey_light',m_glasbey_bw_minc_20_minl_30)
register_cmap('cet_glasbey_light_r',m_glasbey_bw_minc_20_minl_30_r)



Expand Down Expand Up @@ -20454,8 +20406,6 @@ def all_original_names(group=None, not_group=None, only_aliased=False, only_CET=
cm['glasbey_warm_r'] = m_glasbey_bw_minc_20_hue_330_100_r
cm_n['glasbey_warm'] = mpl_cm('glasbey_warm',glasbey_bw_minc_20_hue_330_100)
cm_n['glasbey_warm_r'] = mpl_cm('glasbey_warm_r',list(reversed(glasbey_bw_minc_20_hue_330_100)))
register_cmap('cet_glasbey_warm',m_glasbey_bw_minc_20_hue_330_100)
register_cmap('cet_glasbey_warm_r',m_glasbey_bw_minc_20_hue_330_100_r)



Expand Down Expand Up @@ -20730,8 +20680,6 @@ def all_original_names(group=None, not_group=None, only_aliased=False, only_CET=
cm['glasbey_r'] = m_glasbey_bw_minc_20_r
cm_n['glasbey'] = mpl_cm('glasbey',glasbey_bw_minc_20)
cm_n['glasbey_r'] = mpl_cm('glasbey_r',list(reversed(glasbey_bw_minc_20)))
register_cmap('cet_glasbey',m_glasbey_bw_minc_20)
register_cmap('cet_glasbey_r',m_glasbey_bw_minc_20_r)



Expand Down Expand Up @@ -21271,8 +21219,6 @@ def all_original_names(group=None, not_group=None, only_aliased=False, only_CET=
cm['glasbey_dark_r'] = m_glasbey_bw_minc_20_maxl_70_r
cm_n['glasbey_dark'] = mpl_cm('glasbey_dark',glasbey_bw_minc_20_maxl_70)
cm_n['glasbey_dark_r'] = mpl_cm('glasbey_dark_r',list(reversed(glasbey_bw_minc_20_maxl_70)))
register_cmap('cet_glasbey_dark',m_glasbey_bw_minc_20_maxl_70)
register_cmap('cet_glasbey_dark_r',m_glasbey_bw_minc_20_maxl_70_r)



Expand Down Expand Up @@ -21812,8 +21758,6 @@ def all_original_names(group=None, not_group=None, only_aliased=False, only_CET=
cm['glasbey_cool_r'] = m_glasbey_bw_minc_20_hue_150_280_r
cm_n['glasbey_cool'] = mpl_cm('glasbey_cool',glasbey_bw_minc_20_hue_150_280)
cm_n['glasbey_cool_r'] = mpl_cm('glasbey_cool_r',list(reversed(glasbey_bw_minc_20_hue_150_280)))
register_cmap('cet_glasbey_cool',m_glasbey_bw_minc_20_hue_150_280)
register_cmap('cet_glasbey_cool_r',m_glasbey_bw_minc_20_hue_150_280_r)



Expand Down
5 changes: 5 additions & 0 deletions colorcet/tests/test_matplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,8 @@ def test_matplotlib_default_colormap_plot_kbc():
from colorcet.plotting import swatch
fig = hv.render(swatch('kbc'), backend='matplotlib')
return fig

@pytest.mark.parametrize('k,v', list(cc.cm.items()))
def test_get_cm(k, v):
import matplotlib.cm as mcm
assert mcm.get_cmap('cet_' + k) is v
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# For use with pyctdev (but should work with tox alone)

[tox]
envlist = {py27,py36}-{lint,unit,unit_extra,examples,all}-{default}-{dev,pkg}
envlist = {py27,py36,py37}-{lint,unit,unit_extra,examples,all}-{default}-{dev,pkg}
build = wheel

[_lint]
Expand Down

0 comments on commit e0ff3c7

Please sign in to comment.