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

Skip to content

Commit 59f56af

Browse files
committed
Add image comparison test for bivariate
1 parent 7681d14 commit 59f56af

File tree

6 files changed

+30
-1
lines changed

6 files changed

+30
-1
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5150,7 +5150,8 @@ def imshow(self, X, cmap=None, norm=None, aspect=None,
51505150
"'mcolors.BivariateNorm'")
51515151
raise ValueError(msg)
51525152

5153-
is_bivari = (X.ndim == 3 or X.shape[0] == 2)
5153+
temp = np.asarray(X)
5154+
is_bivari = (temp.ndim == 3 or temp.shape[0] == 2)
51545155
if is_bivari:
51555156
if cmap is None:
51565157
cmap = mcolors.BivariateColormap()

lib/matplotlib/tests/test_axes.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from numpy.testing import assert_allclose, assert_array_equal
2929
from matplotlib.cbook import IgnoredKeywordWarning
3030
from matplotlib.cbook._backports import broadcast_to
31+
from matplotlib.cbook import get_sample_data
3132

3233
# Note: Some test cases are run twice: once normally and once with labeled data
3334
# These two must be defined in the same test function or need to have
@@ -5271,3 +5272,30 @@ def test_twinx_knows_limits():
52715272
def test_zero_linewidth():
52725273
# Check that setting a zero linewidth doesn't error
52735274
plt.plot([0, 1], [0, 1], ls='--', lw=0)
5275+
5276+
5277+
@image_comparison(
5278+
baseline_images=['bivar_imshow', 'bivar_pcolor', 'bivar_pcolormesh',
5279+
'bivar_pcolorfast'],
5280+
extensions=['png']
5281+
)
5282+
def test_bivariates():
5283+
air_temp = np.load(get_sample_data('air_temperature.npy'))
5284+
surf_pres = np.load(get_sample_data('surface_pressure.npy'))
5285+
bivariate = [air_temp, surf_pres]
5286+
5287+
fig1, ax1 = plt.subplots()
5288+
cax1 = ax1.imshow(bivariate)
5289+
cbar = fig1.colorbar(cax1, xlabel='air_temp', ylabel='surf_pres')
5290+
5291+
fig2, ax2 = plt.subplots()
5292+
cax2 = ax2.pcolor(bivariate)
5293+
cbar = fig2.colorbar(cax2, xlabel='air_temp', ylabel='surf_pres')
5294+
5295+
fig3, ax3 = plt.subplots()
5296+
cax3 = ax3.pcolormesh(bivariate)
5297+
cbar = fig3.colorbar(cax3, xlabel='air_temp', ylabel='surf_pres')
5298+
5299+
fig4, ax4 = plt.subplots()
5300+
cax4 = ax4.pcolorfast(bivariate)
5301+
cbar = fig4.colorbar(cax4, xlabel='air_temp', ylabel='surf_pres')

0 commit comments

Comments
 (0)