@@ -2413,39 +2413,38 @@ def plot_wireframe(self, X, Y, Z, *, axlim_clip=False, **kwargs):
24132413 rstride = int (max (np .ceil (rows / rcount ), 1 )) if rcount else 0
24142414 cstride = int (max (np .ceil (cols / ccount ), 1 )) if ccount else 0
24152415
2416+ if rstride == 0 and cstride == 0 :
2417+ raise ValueError ("Either rstride or cstride must be non zero" )
2418+
24162419 # We want two sets of lines, one running along the "rows" of
24172420 # Z and another set of lines running along the "columns" of Z.
24182421 # This transpose will make it easy to obtain the columns.
24192422 tX , tY , tZ = np .transpose (X ), np .transpose (Y ), np .transpose (Z )
24202423
2421- if rstride :
2424+ # Compute the indices of the row and column lines to be drawn
2425+ # For Z.size == 0, we don't want to draw any lines since the data is empty
2426+ if rstride == 0 or Z .size == 0 :
2427+ rii = np .array ([], dtype = int )
2428+ elif (rows - 1 ) % rstride == 0 :
2429+ # last index is hit: rii[-1] == rows - 1
24222430 rii = np .arange (0 , rows , rstride )
2423- # Add the last index only if needed
2424- if rows > 0 and rii [- 1 ] != (rows - 1 ):
2425- rii = np .append (rii , rows - 1 )
24262431 else :
2427- rii = np .array ([], dtype = int )
2432+ # add the last index
2433+ rii = np .arange (0 , rows + rstride , rstride )
2434+ rii [- 1 ] = rows - 1
24282435
2429- if cstride :
2436+ if cstride == 0 or Z .size == 0 :
2437+ cii = np .array ([], dtype = int )
2438+ elif (cols - 1 ) % cstride == 0 :
2439+ # last index is hit: cii[-1] == cols - 1
24302440 cii = np .arange (0 , cols , cstride )
2431- # Add the last index only if needed
2432- if cols > 0 and cii [- 1 ] != (cols - 1 ):
2433- cii = np .append (cii , cols - 1 )
24342441 else :
2435- cii = np .array ([], dtype = int )
2436-
2437- if rstride == 0 and cstride == 0 :
2438- raise ValueError ("Either rstride or cstride must be non zero" )
2439-
2440- # If the inputs were empty, then just
2441- # reset everything.
2442- if Z .size == 0 :
2443- rii = np .array ([], dtype = int )
2444- cii = np .array ([], dtype = int )
2442+ # add the last index
2443+ cii = np .arange (0 , cols + cstride , cstride )
2444+ cii [- 1 ] = cols - 1
24452445
24462446 row_lines = np .stack ([X [rii ], Y [rii ], Z [rii ]], axis = - 1 )
24472447 col_lines = np .stack ([tX [cii ], tY [cii ], tZ [cii ]], axis = - 1 )
2448-
24492448 lines = np .concatenate ([row_lines , col_lines ])
24502449
24512450 linec = art3d .Line3DCollection (lines , axlim_clip = axlim_clip , ** kwargs )
0 commit comments