Skip to content

Commit

Permalink
TST: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
jklymak committed Jul 6, 2022
1 parent bfb7310 commit fda4e5f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/matplotlib/colorbar.py
Expand Up @@ -1212,7 +1212,8 @@ def _reset_locator_formatter_scale(self):
self._minorlocator = None
self._formatter = None
self._minorformatter = None
if isinstance(self.norm, colors.LogNorm):
if (isinstance(self.mappable, contour.ContourSet) and
isinstance(self.norm, colors.LogNorm)):
# if contours have lognorm, give them a log scale...
self._set_scale('log')
elif (self.boundaries is not None or
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions lib/matplotlib/tests/test_contour.py
Expand Up @@ -3,6 +3,7 @@
import re

import contourpy
from matplotlib import ticker
import numpy as np
from numpy.testing import assert_array_almost_equal
import matplotlib as mpl
Expand Down Expand Up @@ -154,6 +155,27 @@ def test_given_colors_levels_and_extends():
plt.colorbar(c, ax=ax)


@image_comparison(['contour_log_locator.png'], style='mpl20', remove_text=True)
def test_log_locator_levels():

fig, ax = plt.subplots()

N = 100
x = np.linspace(-3.0, 3.0, N)
y = np.linspace(-2.0, 2.0, N)

X, Y = np.meshgrid(x, y)

Z1 = np.exp(-X**2 - Y**2)
Z2 = np.exp(-(X * 10)**2 - (Y * 10)**2)
data = Z1 + 50 * Z2

c = ax.contourf(data, locator=ticker.LogLocator())
assert_array_almost_equal(c.levels, np.power(10.0, np.arange(-6, 3)))
cb = fig.colorbar(c, ax=ax)
assert_array_almost_equal(cb.ax.get_yticks(), c.levels)


@image_comparison(['contour_datetime_axis.png'], style='mpl20')
def test_contour_datetime_axis():
fig = plt.figure()
Expand Down

0 comments on commit fda4e5f

Please sign in to comment.