@@ -904,12 +904,37 @@ def plot_wireframe(self, X, Y, Z, *args, **kwargs):
904
904
cstride = kwargs .pop ("cstride" , 1 )
905
905
906
906
had_data = self .has_data ()
907
+ Z = np .atleast_2d (Z )
908
+ # FIXME: Support masked arrays
909
+ X = np .asarray (X )
910
+ Y = np .asarray (Y )
907
911
rows , cols = Z .shape
908
-
912
+ # Force X and Y to take the same shape.
913
+ # If they can not be fitted to that shape,
914
+ # then an exception is automatically thrown.
915
+ X .shape = (rows , cols )
916
+ Y .shape = (rows , cols )
917
+
918
+ # We want two sets of lines, one running along the "rows" of
919
+ # Z and another set of lines running along the "columns" of Z.
920
+ # This transpose will make it easy to obtain the columns.
909
921
tX , tY , tZ = np .transpose (X ), np .transpose (Y ), np .transpose (Z )
910
922
911
- rii = [i for i in range (0 , rows , rstride )]+ [rows - 1 ]
912
- cii = [i for i in range (0 , cols , cstride )]+ [cols - 1 ]
923
+ rii = range (0 , rows , rstride )
924
+ cii = range (0 , cols , cstride )
925
+
926
+ # Add the last index only if needed
927
+ if rows > 0 and rii [- 1 ] != (rows - 1 ) :
928
+ rii += [rows - 1 ]
929
+ if cols > 0 and cii [- 1 ] != (cols - 1 ) :
930
+ cii += [cols - 1 ]
931
+
932
+ # If the inputs were empty, then just
933
+ # reset everything.
934
+ if Z .size == 0 :
935
+ rii = []
936
+ cii = []
937
+
913
938
xlines = [X [i ] for i in rii ]
914
939
ylines = [Y [i ] for i in rii ]
915
940
zlines = [Z [i ] for i in rii ]
@@ -1145,16 +1170,21 @@ def add_collection3d(self, col, zs=0, zdir='z'):
1145
1170
- LineColleciton
1146
1171
- PatchCollection
1147
1172
'''
1173
+ zvals = np .atleast_1d (zs )
1174
+ if len (zvals ) > 0 :
1175
+ zsortval = min (zvals )
1176
+ else :
1177
+ zsortval = 0 # FIXME: Fairly arbitrary. Is there a better value?
1148
1178
1149
1179
if type (col ) is collections .PolyCollection :
1150
1180
art3d .poly_collection_2d_to_3d (col , zs = zs , zdir = zdir )
1151
- col .set_sort_zpos (min ( zs ) )
1181
+ col .set_sort_zpos (zsortval )
1152
1182
elif type (col ) is collections .LineCollection :
1153
1183
art3d .line_collection_2d_to_3d (col , zs = zs , zdir = zdir )
1154
- col .set_sort_zpos (min ( zs ) )
1184
+ col .set_sort_zpos (zsortval )
1155
1185
elif type (col ) is collections .PatchCollection :
1156
1186
art3d .patch_collection_2d_to_3d (col , zs = zs , zdir = zdir )
1157
- col .set_sort_zpos (min ( zs ) )
1187
+ col .set_sort_zpos (zsortval )
1158
1188
1159
1189
Axes .add_collection (self , col )
1160
1190
@@ -1263,7 +1293,14 @@ def bar(self, left, height, zs=0, zdir='z', *args, **kwargs):
1263
1293
if 'alpha' in kwargs :
1264
1294
p .set_alpha (kwargs ['alpha' ])
1265
1295
1266
- xs , ys = zip (* verts )
1296
+ if len (verts ) > 0 :
1297
+ # the following has to be skipped if verts is empty
1298
+ # NOTE: Bugs could still occur if len(verts) > 0,
1299
+ # but the "2nd dimension" is empty.
1300
+ xs , ys = zip (* verts )
1301
+ else :
1302
+ xs , ys = [], []
1303
+
1267
1304
xs , ys , verts_zs = art3d .juggle_axes (xs , ys , verts_zs , zdir )
1268
1305
self .auto_scale_xyz (xs , ys , verts_zs , had_data )
1269
1306
0 commit comments