@@ -38,11 +38,9 @@ def _maybe_centers_to_edges(coord: np.ndarray, M: int, N: int, axis: str) -> np.
3838 expected_edges = expected_centers + 1
3939
4040 if len (coord ) == expected_edges :
41- # Already edges
4241 return coord
4342
4443 if len (coord ) == expected_centers :
45- # Assume centers, convert to edges
4644 edges = np .zeros (expected_edges , dtype = coord .dtype )
4745 # Midpoints between centers, with extrapolation at ends
4846 edges [1 :- 1 ] = 0.5 * (coord [:- 1 ] + coord [1 :])
@@ -58,11 +56,9 @@ def _maybe_centers_to_edges(coord: np.ndarray, M: int, N: int, axis: str) -> np.
5856 elif coord .ndim == 2 :
5957 m , n = coord .shape
6058 if (m , n ) == (M + 1 , N + 1 ):
61- # Already edges
6259 return coord
6360
6461 if (m , n ) == (M , N ):
65- # Assume centers, convert to edges
6662 # Strategy: First pad the coordinate array by extrapolating one
6763 # layer of "ghost" cells around the perimeter, then compute all
6864 # edges as average of 4 surrounding padded centers
@@ -73,13 +69,13 @@ def _maybe_centers_to_edges(coord: np.ndarray, M: int, N: int, axis: str) -> np.
7369 padded [1 :- 1 , 1 :- 1 ] = coord
7470
7571 # Extrapolate edges (sides)
76- # Left edge: coord[:, 0] - (coord[:, 1] - coord[:, 0])
72+ # Left edge
7773 padded [1 :- 1 , 0 ] = coord [:, 0 ] - (coord [:, 1 ] - coord [:, 0 ])
78- # Right edge: coord[:, -1] + (coord[:, -1] - coord[:, -2])
74+ # Right edge
7975 padded [1 :- 1 , - 1 ] = coord [:, - 1 ] + (coord [:, - 1 ] - coord [:, - 2 ])
80- # Bottom edge: coord[0, :] - (coord[1, :] - coord[0, :])
76+ # Bottom edge
8177 padded [0 , 1 :- 1 ] = coord [0 , :] - (coord [1 , :] - coord [0 , :])
82- # Top edge: coord[-1, :] + (coord[-1, :] - coord[-2, :])
78+ # Top edge
8379 padded [- 1 , 1 :- 1 ] = coord [- 1 , :] + (coord [- 1 , :] - coord [- 2 , :])
8480
8581 # Extrapolate corners
@@ -264,19 +260,15 @@ def get_xdata(self) -> np.ndarray:
264260
265261 def set_xdata (self , x : np .ndarray ):
266262 M , N = self ._c .shape
267- self ._x = np .asarray (x )
268- # Convert centers to edges if necessary
269- self ._x = _maybe_centers_to_edges (self ._x , M , N , axis = 'x' )
263+ self ._x = _maybe_centers_to_edges (np .asarray (x ), M , N , axis = 'x' )
270264 self ._update_positions ()
271265
272266 def get_ydata (self ) -> np .ndarray :
273267 return self ._y
274268
275269 def set_ydata (self , y : np .ndarray ):
276270 M , N = self ._c .shape
277- self ._y = np .asarray (y )
278- # Convert centers to edges if necessary
279- self ._y = _maybe_centers_to_edges (self ._y , M , N , axis = 'y' )
271+ self ._y = _maybe_centers_to_edges (np .asarray (y ), M , N , axis = 'y' )
280272 self ._update_positions ()
281273
282274 def set_array (self , c : np .ndarray ):
0 commit comments