@@ -270,6 +270,7 @@ def test2d_1d_2d_coordinates_contourf(self):
270
270
)
271
271
272
272
a .plot .contourf (x = "time" , y = "depth" )
273
+ a .plot .contourf (x = "depth" , y = "time" )
273
274
274
275
def test3d (self ):
275
276
self .darray .plot ()
@@ -2156,6 +2157,34 @@ def test_yticks_kwarg(self, da):
2156
2157
assert np .all (plt .gca ().get_yticks () == expected )
2157
2158
2158
2159
2160
+ @requires_matplotlib
2161
+ @pytest .mark .parametrize ("plotfunc" , ["pcolormesh" , "contourf" , "contour" ])
2162
+ def test_plot_transposed_nondim_coord (plotfunc ):
2163
+ x = np .linspace (0 , 10 , 101 )
2164
+ h = np .linspace (3 , 7 , 101 )
2165
+ s = np .linspace (0 , 1 , 51 )
2166
+ z = s [:, np .newaxis ] * h [np .newaxis , :]
2167
+ da = xr .DataArray (
2168
+ np .sin (x ) * np .cos (z ),
2169
+ dims = ["s" , "x" ],
2170
+ coords = {"x" : x , "s" : s , "z" : (("s" , "x" ), z ), "zt" : (("x" , "s" ), z .T )},
2171
+ )
2172
+ getattr (da .plot , plotfunc )(x = "x" , y = "zt" )
2173
+ getattr (da .plot , plotfunc )(x = "zt" , y = "x" )
2174
+
2175
+
2176
+ @requires_matplotlib
2177
+ @pytest .mark .parametrize ("plotfunc" , ["pcolormesh" , "imshow" ])
2178
+ def test_plot_transposes_properly (plotfunc ):
2179
+ # test that we aren't mistakenly transposing when the 2 dimensions have equal sizes.
2180
+ da = xr .DataArray ([np .sin (2 * np .pi / 10 * np .arange (10 ))] * 10 , dims = ("y" , "x" ))
2181
+ hdl = getattr (da .plot , plotfunc )(x = "x" , y = "y" )
2182
+ # get_array doesn't work for contour, contourf. It returns the colormap intervals.
2183
+ # pcolormesh returns 1D array but imshow returns a 2D array so it is necessary
2184
+ # to ravel() on the LHS
2185
+ assert np .all (hdl .get_array ().ravel () == da .to_masked_array ().ravel ())
2186
+
2187
+
2159
2188
@requires_matplotlib
2160
2189
class TestDataArrayGroupByPlot :
2161
2190
@requires_cftime
0 commit comments