99line segments).
1010"""
1111
12+ import inspect
1213import math
1314from numbers import Number
15+ import warnings
16+
1417import numpy as np
1518
1619import matplotlib as mpl
1720from . import (_api , _path , artist , cbook , cm , colors as mcolors , docstring ,
1821 hatch as mhatch , lines as mlines , path as mpath , transforms )
1922from ._enums import JoinStyle , CapStyle
20- import warnings
2123
2224
2325# "color" is excluded; it is a compound setter, and its docstring differs
@@ -1931,6 +1933,35 @@ class QuadMesh(Collection):
19311933 """
19321934 Class for the efficient drawing of a quadrilateral mesh.
19331935
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+
19341965 A quadrilateral mesh consists of a grid of vertices.
19351966 The dimensions of this array are (*meshWidth* + 1, *meshHeight* + 1).
19361967 Each vertex in the mesh has a different set of "mesh coordinates"
@@ -1954,22 +1985,55 @@ class QuadMesh(Collection):
19541985 vertex at mesh coordinates (0, 0), then the one at (0, 1), then at (0, 2)
19551986 .. (0, meshWidth), (1, 0), (1, 1), and so on.
19561987
1957- *shading* may be 'flat', or 'gouraud'
19581988 """
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+
19612022 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
19672027 self ._antialiased = antialiased
19682028 self ._shading = shading
19692029
19702030 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 )
19732037
19742038 def get_paths (self ):
19752039 if self ._paths is None :
0 commit comments