9
9
line segments).
10
10
"""
11
11
12
+ import inspect
12
13
import math
13
14
from numbers import Number
15
+ import warnings
16
+
14
17
import numpy as np
15
18
16
19
import matplotlib as mpl
17
20
from . import (_api , _path , artist , cbook , cm , colors as mcolors , docstring ,
18
21
hatch as mhatch , lines as mlines , path as mpath , transforms )
19
22
from ._enums import JoinStyle , CapStyle
20
- import warnings
21
23
22
24
23
25
# "color" is excluded; it is a compound setter, and its docstring differs
@@ -1931,6 +1933,35 @@ class QuadMesh(Collection):
1931
1933
"""
1932
1934
Class for the efficient drawing of a quadrilateral mesh.
1933
1935
1936
+ A quadrilateral mesh is a grid of M by N adjacent qudrilaterals that are
1937
+ defined via a (M+1, N+1) grid of vertices. The quadrilateral (m, n) is
1938
+ defind by the vertices ::
1939
+
1940
+ (m+1, n) ----------- (m+1, n+1)
1941
+ / /
1942
+ / /
1943
+ / /
1944
+ (m, n) -------- (m, n+1)
1945
+
1946
+ The mesh need not be regular and the polygons need not be convex.
1947
+
1948
+ Parameters
1949
+ ----------
1950
+ coordinates : (M+1, N+1, 2) array-like
1951
+ The vertices. ``coordinates[m, n]`` specifies the (x, y) coordinates
1952
+ of vertex (m, n).
1953
+
1954
+ antialiased : bool, default: True
1955
+
1956
+ shading : {'flat', 'gouraud'}, default: 'flat'
1957
+
1958
+ Notes
1959
+ -----
1960
+ There exists a deprecated API version ``QuadMesh(M, N, coords)``, where
1961
+ the dimensions are given explicitly and ``coords`` is a (M*N, 2)
1962
+ array-like. This has been deprecated in Matplotlib 3.5. The following
1963
+ describes the semantics of this deprecated API.
1964
+
1934
1965
A quadrilateral mesh consists of a grid of vertices.
1935
1966
The dimensions of this array are (*meshWidth* + 1, *meshHeight* + 1).
1936
1967
Each vertex in the mesh has a different set of "mesh coordinates"
@@ -1954,22 +1985,55 @@ class QuadMesh(Collection):
1954
1985
vertex at mesh coordinates (0, 0), then the one at (0, 1), then at (0, 2)
1955
1986
.. (0, meshWidth), (1, 0), (1, 1), and so on.
1956
1987
1957
- *shading* may be 'flat', or 'gouraud'
1958
1988
"""
1959
- def __init__ (self , meshWidth , meshHeight , coordinates ,
1960
- antialiased = True , shading = 'flat' , ** kwargs ):
1989
+ def __init__ (self , * args , ** kwargs ):
1990
+ # signature deprecation since="3.5": Change to new signature after the
1991
+ # deprecation has expired. Also remove setting __init__.__signature__,
1992
+ # and remove the Notes from the docstring.
1993
+ #
1994
+ # We use lambdas to parse *args, **kwargs through the respective old
1995
+ # and new signatures.
1996
+ try :
1997
+ # Old signature:
1998
+ # The following raises a TypeError iif the args don't match.
1999
+ w , h , coords , antialiased , shading , kwargs = (
2000
+ lambda meshWidth , meshHeight , coordinates , antialiased = True ,
2001
+ shading = False , ** kwargs :
2002
+ (meshWidth , meshHeight , coordinates , antialiased , shading ,
2003
+ kwargs ))(* args , ** kwargs )
2004
+ except TypeError as exc :
2005
+ # New signature:
2006
+ # If the following raises a TypeError (i.e. args don't match),
2007
+ # just let it propagate.
2008
+ coords , antialiased , shading , kwargs = (
2009
+ lambda coordinates , antialiased = True , shading = False , ** kwargs :
2010
+ (coordinates , antialiased , shading , kwargs ))(* args , ** kwargs )
2011
+ coords = np .asarray (coords , np .float64 )
2012
+ else : # The old signature matched.
2013
+ _api .warn_deprecated (
2014
+ "3.5" ,
2015
+ message = "This usage of Quadmesh is deprecated: Parameters "
2016
+ "meshWidth and meshHeights will be removed; "
2017
+ "coordinates must be 2D; all parameters except "
2018
+ "coordinates will be keyword-only." )
2019
+ coords = np .asarray (coords , np .float64 ).reshape ((h + 1 , w + 1 , 2 ))
2020
+ # end of signature deprecation code
2021
+
1961
2022
super ().__init__ (** kwargs )
1962
- self ._meshWidth = meshWidth
1963
- self ._meshHeight = meshHeight
1964
- # By converting to floats now, we can avoid that on every draw.
1965
- self ._coordinates = np .asarray (coordinates , float ).reshape (
1966
- (meshHeight + 1 , meshWidth + 1 , 2 ))
2023
+ _api .check_shape ((None , None , 2 ), coordinates = coords )
2024
+ self ._coordinates = coords
2025
+ self ._meshWidth = self ._coordinates .shape [1 ] - 1
2026
+ self ._meshHeight = self ._coordinates .shape [0 ] - 1
1967
2027
self ._antialiased = antialiased
1968
2028
self ._shading = shading
1969
2029
1970
2030
self ._bbox = transforms .Bbox .unit ()
1971
- self ._bbox .update_from_data_xy (coordinates .reshape (
1972
- ((meshWidth + 1 ) * (meshHeight + 1 ), 2 )))
2031
+ self ._bbox .update_from_data_xy (self ._coordinates .reshape (- 1 , 2 ))
2032
+
2033
+ # Only needed during signature deprecation
2034
+ __init__ .__signature__ = inspect .signature (
2035
+ lambda self , coordinates , * ,
2036
+ antialiased = True , shading = 'flat' , ** kwargs : None )
1973
2037
1974
2038
def get_paths (self ):
1975
2039
if self ._paths is None :
0 commit comments