-
Notifications
You must be signed in to change notification settings - Fork 24
Fix contour level color mapping with explicit limits #599
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
6c87a64
47f070f
bdbc5ff
bf1dd57
bddbcd6
21195ec
e7b881a
e5c3116
940ac89
574bcd0
fd44af3
0008b82
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4555,6 +4555,8 @@ def _parse_level_vals( | |
| nozero=False, | ||
| norm=None, | ||
| norm_kw=None, | ||
| vmin=None, | ||
| vmax=None, | ||
| skip_autolev=False, | ||
| min_levels=None, | ||
| center_levels=None, | ||
|
|
@@ -4578,6 +4580,8 @@ def _parse_level_vals( | |
| levels. The latter is useful for single-color contour plots. | ||
| norm, norm_kw : optional | ||
| Passed to `Norm`. Used to possbily infer levels or to convert values. | ||
| vmin, vmax : float, optional | ||
| The user input normalization range. | ||
| skip_autolev : bool, optional | ||
| Whether to skip automatic level generation. | ||
| min_levels : int, optional | ||
|
|
@@ -4625,7 +4629,6 @@ def _sanitize_levels(key, array, minsize): | |
| return array | ||
|
|
||
| # Parse input arguments and resolve incompatibilities | ||
| vmin = vmax = None | ||
| levels = _not_none(N=N, levels=levels, norm_kw_levs=norm_kw.pop("levels", None)) | ||
| if positive and negative: | ||
| warnings._warn_ultraplot( | ||
|
|
@@ -4696,18 +4699,23 @@ def _sanitize_levels(key, array, minsize): | |
| levels = values = None | ||
|
|
||
| # Determine default colorbar locator and norm and apply filters | ||
| # NOTE: DiscreteNorm does not currently support vmin and | ||
| # vmax different from level list minimum and maximum. | ||
| # NOTE: Explicit vmin/vmax should override defaults inferred from levels. | ||
| # NOTE: The level restriction should have no effect if levels were generated | ||
| # automatically. However want to apply these to manual-input levels as well. | ||
| if levels is not None: | ||
| levels = _restrict_levels(levels) | ||
| if len(levels) == 0: # skip | ||
| pass | ||
| elif len(levels) == 1: # use central colormap color | ||
| vmin, vmax = levels[0] - 1, levels[0] + 1 | ||
| if vmin is None: | ||
| vmin = levels[0] - 1 | ||
| if vmax is None: | ||
| vmax = levels[0] + 1 | ||
| else: # use minimum and maximum | ||
| vmin, vmax = np.min(levels), np.max(levels) | ||
| if vmin is None: | ||
| vmin = np.min(levels) | ||
| if vmax is None: | ||
| vmax = np.max(levels) | ||
| if not np.allclose(levels[1] - levels[0], np.diff(levels)): | ||
| norm = _not_none(norm, "segmented") | ||
| if norm in ("segments", "segmented"): | ||
|
|
@@ -4814,10 +4822,15 @@ def _parse_level_norm( | |
| elif extend == "max": | ||
| unique = "neither" | ||
|
|
||
| # Generate DiscreteNorm and update "child" norm with vmin and vmax from | ||
| # levels. This lets the colorbar set tick locations properly! | ||
| # Generate DiscreteNorm for filled-contour style bins. For line contours | ||
| # (`min_levels == 1`) levels represent contour values, so keep the | ||
| # continuous normalizer to preserve one-to-one value->color mapping. | ||
| center_levels = _not_none(center_levels, rc["colorbar.center_levels"]) | ||
|
Comment on lines
+4846
to
4849
|
||
| if not isinstance(norm, mcolors.BoundaryNorm) and len(levels) > 1: | ||
| if ( | ||
| min_levels != 1 | ||
| and not isinstance(norm, mcolors.BoundaryNorm) | ||
| and len(levels) > 1 | ||
| ): | ||
| norm = pcolors.DiscreteNorm( | ||
| levels, | ||
| norm=norm, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.