|
54 | 54 | 'Colors', # deprecated |
55 | 55 | ] |
56 | 56 |
|
57 | | -# Dictionary of possible normalizers. See `Norm` for a table. |
| 57 | +# Color cycle constants |
| 58 | +# TODO: Also automatically truncate the 'bright' end of colormaps |
| 59 | +# when building color cycles from colormaps? Or add simple option. |
| 60 | +DEFAULT_CYCLE_SAMPLES = 10 |
| 61 | +DEFAULT_CYCLE_LUMINANCE = 90 |
| 62 | + |
| 63 | +# Normalizer registry |
58 | 64 | NORMS = { |
59 | 65 | 'none': mcolors.NoNorm, |
60 | 66 | 'null': mcolors.NoNorm, |
|
70 | 76 | if hasattr(mcolors, 'TwoSlopeNorm'): |
71 | 77 | NORMS['twoslope'] = mcolors.TwoSlopeNorm |
72 | 78 |
|
73 | | -# Mapping of strings to `~matplotlib.ticker.Locator` classes. See |
74 | | -# `Locator` for a table.""" |
| 79 | +# Locator registry |
75 | 80 | LOCATORS = { |
76 | 81 | 'none': mticker.NullLocator, |
77 | 82 | 'null': mticker.NullLocator, |
|
101 | 106 | } |
102 | 107 | if dependencies._version_cartopy >= 0.18: |
103 | 108 | # NOTE: This only makes sense when paired with degree-minute-second formatter |
104 | | - # NOTE: We copied cartopy locators because they are short and necessary |
105 | | - # for determining both cartopy and basemap tick locations. We did *not* copy |
106 | | - # formatter because they are long and we have nice, simpler alternatives of |
107 | | - # deglon and deglat. |
108 | 109 | LOCATORS['dms'] = partial(pticker.DegreeLocator, dms=True) |
109 | 110 | LOCATORS['dmslon'] = partial(pticker.LongitudeLocator, dms=True) |
110 | 111 | LOCATORS['dmslat'] = partial(pticker.LatitudeLocator, dms=True) |
111 | 112 | if hasattr(mproj.polar, 'ThetaLocator'): |
112 | 113 | LOCATORS['theta'] = mproj.polar.ThetaLocator |
113 | 114 |
|
114 | | -# Mapping of strings to `~matplotlib.ticker.Formatter` classes. See |
115 | | -# `Formatter` for a table. |
| 115 | +# Formatter registry |
116 | 116 | # NOTE: Critical to use SimpleFormatter for cardinal formatters rather than |
117 | 117 | # AutoFormatter because latter fails with Basemap formatting. |
118 | 118 | # NOTE: Define cartopy longitude/latitude formatters with dms=True because that |
|
156 | 156 | if hasattr(mdates, 'ConciseDateFormatter'): |
157 | 157 | FORMATTERS['concise'] = mdates.ConciseDateFormatter |
158 | 158 |
|
159 | | -# The registered scale names and their associated |
160 | | -# `~matplotlib.scale.ScaleBase` classes. See `Scale` for a table. |
| 159 | +# Scale registry and presets |
161 | 160 | SCALES = mscale._scale_mapping |
162 | 161 | SCALE_PRESETS = { |
163 | 162 | 'quadratic': ('power', 2,), |
|
182 | 181 | mscale.register_scale(pscale.SineLatitudeScale) |
183 | 182 | mscale.register_scale(pscale.SymmetricalLogScale) |
184 | 183 |
|
185 | | -# Mapping of "projection names" to cartopy `~cartopy.crs.Projection` classes |
186 | | -# and default keyword args for `~mpl_toolkits.basemap.Basemap` projections. |
| 184 | +# Cartopy projection registry and default basemap keyword args |
187 | 185 | # NOTE: Normally basemap raises error if you omit keyword args |
188 | 186 | PROJ_ALIASES = { # aliases to basemap naming conventions |
189 | 187 | 'eqc': 'cyl', |
|
296 | 294 | + ' . Please consider updating cartopy.' |
297 | 295 | ) |
298 | 296 |
|
299 | | -# Resolution aliases |
300 | | -# NOTE: Maximum basemap resolutions are much finer than cartopy |
301 | | -RESOS_CARTOPY = { |
302 | | - 'lo': '110m', |
303 | | - 'med': '50m', |
304 | | - 'hi': '10m', |
305 | | - 'x-hi': '10m', # extra high |
306 | | - 'xx-hi': '10m', # extra extra high |
307 | | -} |
308 | | -RESOS_BASEMAP = { |
309 | | - 'lo': 'c', # coarse |
310 | | - 'med': 'l', |
311 | | - 'hi': 'i', # intermediate |
312 | | - 'x-hi': 'h', |
313 | | - 'xx-hi': 'f', # fine |
314 | | -} |
315 | | - |
316 | 297 | # Geographic feature properties |
317 | 298 | FEATURES_CARTOPY = { # positional arguments passed to NaturalEarthFeature |
318 | 299 | 'land': ('physical', 'land'), |
|
331 | 312 | 'innerborders': 'drawstates', |
332 | 313 | } |
333 | 314 |
|
| 315 | +# Resolution names |
| 316 | +# NOTE: Maximum basemap resolutions are much finer than cartopy |
| 317 | +RESOS_CARTOPY = { |
| 318 | + 'lo': '110m', |
| 319 | + 'med': '50m', |
| 320 | + 'hi': '10m', |
| 321 | + 'x-hi': '10m', # extra high |
| 322 | + 'xx-hi': '10m', # extra extra high |
| 323 | +} |
| 324 | +RESOS_BASEMAP = { |
| 325 | + 'lo': 'c', # coarse |
| 326 | + 'med': 'l', |
| 327 | + 'hi': 'i', # intermediate |
| 328 | + 'x-hi': 'h', |
| 329 | + 'xx-hi': 'f', # fine |
| 330 | +} |
| 331 | + |
334 | 332 |
|
335 | 333 | def _modify_colormap(cmap, *, cut, left, right, reverse, shift, alpha, samples): |
336 | 334 | """ |
@@ -675,7 +673,7 @@ def _pop_modification(key): |
675 | 673 |
|
676 | 674 | # Modify the colormap |
677 | 675 | if discrete and isinstance(cmap, pcolors.ContinuousColormap): # noqa: E501 |
678 | | - samples = _not_none(samples, pcolors.DEFAULT_SAMPLES) |
| 676 | + samples = _not_none(samples, DEFAULT_CYCLE_SAMPLES) |
679 | 677 | cmap = _modify_colormap( |
680 | 678 | cmap, cut=cut, left=left, right=right, |
681 | 679 | reverse=reverse, shift=shift, alpha=alpha, samples=samples |
@@ -818,7 +816,7 @@ def Cycle(*args, N=None, samples=None, name=None, **kwargs): |
818 | 816 | kwargs.setdefault('listmode', 'discrete') |
819 | 817 | kwargs.setdefault('filemode', 'discrete') |
820 | 818 | kwargs['discrete'] = True # triggers application of default 'samples' |
821 | | - kwargs['default_luminance'] = pcolors.CYCLE_LUMINANCE |
| 819 | + kwargs['default_luminance'] = DEFAULT_CYCLE_LUMINANCE |
822 | 820 | cmap = Colormap(*args, name=name, samples=samples, **kwargs) |
823 | 821 | name = _not_none(name, cmap.name) |
824 | 822 | dict_ = {'color': [c if isinstance(c, str) else to_hex(c) for c in cmap.colors]} |
|
0 commit comments