Skip to content

Commit fda4e5f

Browse files
committed
TST: add test
1 parent bfb7310 commit fda4e5f

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

lib/matplotlib/colorbar.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1212,7 +1212,8 @@ def _reset_locator_formatter_scale(self):
12121212
self._minorlocator = None
12131213
self._formatter = None
12141214
self._minorformatter = None
1215-
if isinstance(self.norm, colors.LogNorm):
1215+
if (isinstance(self.mappable, contour.ContourSet) and
1216+
isinstance(self.norm, colors.LogNorm)):
12161217
# if contours have lognorm, give them a log scale...
12171218
self._set_scale('log')
12181219
elif (self.boundaries is not None or

lib/matplotlib/tests/test_contour.py

+22
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import re
44

55
import contourpy
6+
from matplotlib import ticker
67
import numpy as np
78
from numpy.testing import assert_array_almost_equal
89
import matplotlib as mpl
@@ -154,6 +155,27 @@ def test_given_colors_levels_and_extends():
154155
plt.colorbar(c, ax=ax)
155156

156157

158+
@image_comparison(['contour_log_locator.png'], style='mpl20', remove_text=True)
159+
def test_log_locator_levels():
160+
161+
fig, ax = plt.subplots()
162+
163+
N = 100
164+
x = np.linspace(-3.0, 3.0, N)
165+
y = np.linspace(-2.0, 2.0, N)
166+
167+
X, Y = np.meshgrid(x, y)
168+
169+
Z1 = np.exp(-X**2 - Y**2)
170+
Z2 = np.exp(-(X * 10)**2 - (Y * 10)**2)
171+
data = Z1 + 50 * Z2
172+
173+
c = ax.contourf(data, locator=ticker.LogLocator())
174+
assert_array_almost_equal(c.levels, np.power(10.0, np.arange(-6, 3)))
175+
cb = fig.colorbar(c, ax=ax)
176+
assert_array_almost_equal(cb.ax.get_yticks(), c.levels)
177+
178+
157179
@image_comparison(['contour_datetime_axis.png'], style='mpl20')
158180
def test_contour_datetime_axis():
159181
fig = plt.figure()

0 commit comments

Comments
 (0)