|
7 | 7 | from numpy.testing import assert_array_almost_equal |
8 | 8 | import matplotlib as mpl |
9 | 9 | from matplotlib.testing.decorators import image_comparison |
10 | | -from matplotlib import pyplot as plt, rc_context |
| 10 | +from matplotlib import pyplot as plt, rc_context, ticker |
11 | 11 | from matplotlib.colors import LogNorm, same_color |
12 | 12 | import pytest |
13 | 13 |
|
@@ -154,6 +154,27 @@ def test_given_colors_levels_and_extends(): |
154 | 154 | plt.colorbar(c, ax=ax) |
155 | 155 |
|
156 | 156 |
|
| 157 | +@image_comparison(['contour_log_locator.png'], style='mpl20', remove_text=True) |
| 158 | +def test_log_locator_levels(): |
| 159 | + |
| 160 | + fig, ax = plt.subplots() |
| 161 | + |
| 162 | + N = 100 |
| 163 | + x = np.linspace(-3.0, 3.0, N) |
| 164 | + y = np.linspace(-2.0, 2.0, N) |
| 165 | + |
| 166 | + X, Y = np.meshgrid(x, y) |
| 167 | + |
| 168 | + Z1 = np.exp(-X**2 - Y**2) |
| 169 | + Z2 = np.exp(-(X * 10)**2 - (Y * 10)**2) |
| 170 | + data = Z1 + 50 * Z2 |
| 171 | + |
| 172 | + c = ax.contourf(data, locator=ticker.LogLocator()) |
| 173 | + assert_array_almost_equal(c.levels, np.power(10.0, np.arange(-6, 3))) |
| 174 | + cb = fig.colorbar(c, ax=ax) |
| 175 | + assert_array_almost_equal(cb.ax.get_yticks(), c.levels) |
| 176 | + |
| 177 | + |
157 | 178 | @image_comparison(['contour_datetime_axis.png'], style='mpl20') |
158 | 179 | def test_contour_datetime_axis(): |
159 | 180 | fig = plt.figure() |
|
0 commit comments