@@ -1594,7 +1594,11 @@ def plot_surface(self, X, Y, Z, *args, norm=None, vmin=None,
1594
1594
Bounds for the normalization.
1595
1595
1596
1596
shade : bool
1597
- Whether to shade the face colors.
1597
+ Whether to shade the facecolors. Defaults to True. Shading is
1598
+ always disabled when `cmap` is specified.
1599
+
1600
+ lightsource : `~matplotlib.colors.LightSource`
1601
+ The lightsource to use when `shade` is True.
1598
1602
1599
1603
**kwargs :
1600
1604
Other arguments are forwarded to `.Poly3DCollection`.
@@ -1645,10 +1649,6 @@ def plot_surface(self, X, Y, Z, *args, norm=None, vmin=None,
1645
1649
cmap = kwargs .get ('cmap' , None )
1646
1650
shade = kwargs .pop ('shade' , cmap is None )
1647
1651
1648
- # Shade the data
1649
- if shade and cmap is not None and fcolors is not None :
1650
- fcolors = self ._shade_colors_lightsource (Z , cmap , lightsource )
1651
-
1652
1652
# evenly spaced, and including both endpoints
1653
1653
row_inds = list (range (0 , rows - 1 , rstride )) + [rows - 1 ]
1654
1654
col_inds = list (range (0 , cols - 1 , cstride )) + [cols - 1 ]
@@ -1689,7 +1689,7 @@ def get_normals(polygons):
1689
1689
1690
1690
if fcolors is not None :
1691
1691
if shade :
1692
- colset = self ._shade_colors (colset , get_normals (polys ))
1692
+ colset = self ._shade_colors (colset , get_normals (polys ), lightsource )
1693
1693
polyc .set_facecolors (colset )
1694
1694
polyc .set_edgecolors (colset )
1695
1695
elif cmap :
@@ -1702,7 +1702,7 @@ def get_normals(polygons):
1702
1702
polyc .set_norm (norm )
1703
1703
else :
1704
1704
if shade :
1705
- colset = self ._shade_colors (color , get_normals (polys ))
1705
+ colset = self ._shade_colors (color , get_normals (polys ), lightsource )
1706
1706
else :
1707
1707
colset = color
1708
1708
polyc .set_facecolors (colset )
@@ -1726,13 +1726,16 @@ def _generate_normals(self, polygons):
1726
1726
normals .append (np .cross (v1 , v2 ))
1727
1727
return normals
1728
1728
1729
- def _shade_colors (self , color , normals ):
1729
+ def _shade_colors (self , color , normals , lightsource = None ):
1730
1730
'''
1731
1731
Shade *color* using normal vectors given by *normals*.
1732
1732
*color* can also be an array of the same length as *normals*.
1733
1733
'''
1734
+ if lightsource is None :
1735
+ # chosen for backwards-compatibility
1736
+ lightsource = LightSource (azdeg = 225 , altdeg = 19.4712 )
1734
1737
1735
- shade = np .array ([np .dot (n / proj3d .mod (n ), [ - 1 , - 1 , 0.5 ] )
1738
+ shade = np .array ([np .dot (n / proj3d .mod (n ), lightsource . direction )
1736
1739
if proj3d .mod (n ) else np .nan
1737
1740
for n in normals ])
1738
1741
mask = ~ np .isnan (shade )
@@ -1752,11 +1755,6 @@ def _shade_colors(self, color, normals):
1752
1755
1753
1756
return colors
1754
1757
1755
- def _shade_colors_lightsource (self , data , cmap , lightsource ):
1756
- if lightsource is None :
1757
- lightsource = LightSource (azdeg = 135 , altdeg = 55 )
1758
- return lightsource .shade (data , cmap )
1759
-
1760
1758
def plot_wireframe (self , X , Y , Z , * args , ** kwargs ):
1761
1759
"""
1762
1760
Plot a 3D wireframe.
@@ -1880,17 +1878,7 @@ def plot_wireframe(self, X, Y, Z, *args, **kwargs):
1880
1878
def plot_trisurf (self , * args , color = None , norm = None , vmin = None , vmax = None ,
1881
1879
lightsource = None , ** kwargs ):
1882
1880
"""
1883
- ============= ================================================
1884
- Argument Description
1885
- ============= ================================================
1886
- *X*, *Y*, *Z* Data values as 1D arrays
1887
- *color* Color of the surface patches
1888
- *cmap* A colormap for the surface patches.
1889
- *norm* An instance of Normalize to map values to colors
1890
- *vmin* Minimum value to map
1891
- *vmax* Maximum value to map
1892
- *shade* Whether to shade the facecolors
1893
- ============= ================================================
1881
+ Plot a triangulated surface.
1894
1882
1895
1883
The (optional) triangulation can be specified in one of two ways;
1896
1884
either::
@@ -1915,10 +1903,29 @@ def plot_trisurf(self, *args, color=None, norm=None, vmin=None, vmax=None,
1915
1903
where *Z* is the array of values to contour, one per point
1916
1904
in the triangulation.
1917
1905
1918
- Other arguments are passed on to
1919
- :class:`~mpl_toolkits.mplot3d.art3d.Poly3DCollection`
1906
+ Parameters
1907
+ ----------
1908
+ X, Y, Z : array-like
1909
+ Data values as 1D arrays.
1910
+ color
1911
+ Color of the surface patches.
1912
+ cmap
1913
+ A colormap for the surface patches.
1914
+ norm : Normalize
1915
+ An instance of Normalize to map values to colors.
1916
+ vmin, vmax : scalar, optional, default: None
1917
+ Minimum and maximum value to map.
1918
+ shade : bool
1919
+ Whether to shade the facecolors. Defaults to True. Shading is
1920
+ always disabled when *cmap* is specified.
1921
+ lightsource : `~matplotlib.colors.LightSource`
1922
+ The lightsource to use when *shade* is True.
1923
+ **kwargs
1924
+ All other arguments are passed on to
1925
+ :class:`~mpl_toolkits.mplot3d.art3d.Poly3DCollection`
1920
1926
1921
- **Examples:**
1927
+ Examples
1928
+ --------
1922
1929
1923
1930
.. plot:: gallery/mplot3d/trisurf3d.py
1924
1931
.. plot:: gallery/mplot3d/trisurf3d_2.py
@@ -1967,7 +1974,7 @@ def plot_trisurf(self, *args, color=None, norm=None, vmin=None, vmax=None,
1967
1974
v1 = verts [:, 0 , :] - verts [:, 1 , :]
1968
1975
v2 = verts [:, 1 , :] - verts [:, 2 , :]
1969
1976
normals = np .cross (v1 , v2 )
1970
- colset = self ._shade_colors (color , normals )
1977
+ colset = self ._shade_colors (color , normals , lightsource )
1971
1978
else :
1972
1979
colset = color
1973
1980
polyc .set_facecolors (colset )
0 commit comments