Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit efc504b

Browse files
authored
Merge pull request #11610 from jklymak/fix-extend-low-powernorm
FIX: let colorbar extends work for PowerNorm
2 parents 553a395 + 092e4da commit efc504b

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

lib/matplotlib/colorbar.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -828,8 +828,9 @@ def _process_values(self, b=None):
828828

829829
b = self.norm.inverse(self._uniform_y(self.cmap.N + 1))
830830

831-
if isinstance(self.norm, colors.LogNorm):
832-
# If using a lognorm, ensure extensions don't go negative
831+
if isinstance(self.norm, (colors.PowerNorm, colors.LogNorm)):
832+
# If using a lognorm or powernorm, ensure extensions don't
833+
# go negative
833834
if self._extend_lower():
834835
b[0] = 0.9 * b[0]
835836
if self._extend_upper():

lib/matplotlib/tests/test_colorbar.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from matplotlib import rc_context
55
from matplotlib.testing.decorators import image_comparison
66
import matplotlib.pyplot as plt
7-
from matplotlib.colors import BoundaryNorm, LogNorm
7+
from matplotlib.colors import BoundaryNorm, LogNorm, PowerNorm
88
from matplotlib.cm import get_cmap
99
from matplotlib.colorbar import ColorbarBase
1010

@@ -372,6 +372,14 @@ def test_colorbar_lognorm_extension():
372372
assert cb._values[0] >= 0.0
373373

374374

375+
def test_colorbar_powernorm_extension():
376+
# Test that colorbar with powernorm is extended correctly
377+
f, ax = plt.subplots()
378+
cb = ColorbarBase(ax, norm=PowerNorm(gamma=0.5, vmin=0.0, vmax=1.0),
379+
orientation='vertical', extend='both')
380+
assert cb._values[0] >= 0.0
381+
382+
375383
def test_colorbar_axes_kw():
376384
# test fix for #8493: This does only test, that axes-related keywords pass
377385
# and do not raise an exception.

0 commit comments

Comments
 (0)