Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2e9bc18

Browse files
committed
API: add api functions
MNT: rename variadic keywords for consistency DOC: udate docstrings TST: refactor tests
1 parent 96f79ee commit 2e9bc18

File tree

1 file changed

+113
-0
lines changed

1 file changed

+113
-0
lines changed

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2838,6 +2838,10 @@ def bar3d(self, x, y, z, dx, dy, dz, color=None,
28382838
Any additional keyword arguments are passed onto
28392839
`~.art3d.Poly3DCollection`.
28402840
2841+
See Also
2842+
--------
2843+
mpl_toolkits.mplot3d.axes3d.Axes3D.bar3d_grid
2844+
28412845
Returns
28422846
-------
28432847
collection : `~.art3d.Poly3DCollection`
@@ -2943,6 +2947,115 @@ def bar3d(self, x, y, z, dx, dy, dz, color=None,
29432947

29442948
return col
29452949

2950+
@_preprocess_data()
2951+
def bar3d_grid(self, x, y, z, dxy='0.8', z0=0, **kwargs):
2952+
"""
2953+
Generate a 3D barplot.
2954+
2955+
This method creates three-dimensional barplot for bars on a regular
2956+
xy-grid and on the same level z-plane. Color of the bars can be
2957+
set uniquely, or cmap can be provided to map the bar heights *z* to
2958+
colors.
2959+
2960+
Parameters
2961+
----------
2962+
x, y : array-like
2963+
The coordinates of the anchor point of the bars.
2964+
2965+
z : array-like
2966+
The height of the bars.
2967+
2968+
dxy : str, tuple[str], optional
2969+
Width of the bars as a fraction of the data step, by default '0.8'
2970+
2971+
z0 : float
2972+
z-position of the base of the bars. All bars share the same base
2973+
value.
2974+
2975+
data : indexable object, optional
2976+
DATA_PARAMETER_PLACEHOLDER
2977+
2978+
**kwargs
2979+
Any additional keyword arguments are forwarded to
2980+
`~.art3d.Poly3DCollection`.
2981+
2982+
See Also
2983+
--------
2984+
mpl_toolkits.mplot3d.axes3d.Axes3D.bar3d
2985+
2986+
Returns
2987+
-------
2988+
bars : `~.art3d.Bar3DCollection`
2989+
A collection of three-dimensional polygons representing the bars
2990+
(rectangular prisms).
2991+
"""
2992+
2993+
bars = art3d.Bar3DCollection(x, y, z, dxy, z0, **kwargs)
2994+
self.add_collection(bars)
2995+
2996+
# compute axes limits
2997+
viewlim = np.array([(np.min(x), np.max(x) + bars.dx),
2998+
(np.min(y), np.max(y) + bars.dy),
2999+
(min(bars.z0, np.min(z)), np.max(z))])
3000+
3001+
self.auto_scale_xyz(*viewlim, False)
3002+
3003+
return bars
3004+
3005+
@_preprocess_data()
3006+
def hexbar3d(self, x, y, z, dxy='0.8', z0=0, **kwargs):
3007+
"""
3008+
This method creates three-dimensional barplot with hexagonal bars for a
3009+
regular xy-grid on the same level z-plane. Color of the bars can be set
3010+
uniquely, or cmap can be provided to map the bar heights *z* to colors.
3011+
3012+
Parameters
3013+
----------
3014+
x, y: array-like
3015+
The coordinates of the anchor point of the bars.
3016+
3017+
z: array-like
3018+
The height of the bars.
3019+
3020+
dxy : str, optional
3021+
_description_, by default '0.8'
3022+
3023+
z0 : float
3024+
z-position of the base of the bars. All bars share the same base
3025+
value.
3026+
3027+
data : indexable object, optional
3028+
DATA_PARAMETER_PLACEHOLDER
3029+
3030+
**kwargs
3031+
Any additional keyword arguments are forwarded to
3032+
`~.art3d.Poly3DCollection`.
3033+
3034+
See Also
3035+
--------
3036+
mpl_toolkits.mplot3d.axes3d.Axes3D.bar3d
3037+
3038+
Returns
3039+
-------
3040+
bars : `~.art3d.HexBar3DCollection`
3041+
A collection of three-dimensional polygons representing the bars
3042+
(hexagonal prisms).
3043+
"""
3044+
3045+
bars = art3d.HexBar3DCollection(x, y, z, dxy, z0, **kwargs)
3046+
self.add_collection(bars)
3047+
3048+
# compute axes limits
3049+
dx = bars.dx / 2
3050+
dy = bars.dy / 2 #/ np.sqrt(3)
3051+
viewlim = np.array([(np.min(x) - dx, np.max(x) + dx),
3052+
(np.min(y) - dy, np.max(y) + dy),
3053+
(min(bars.z0, np.min(z)), np.max(z))])
3054+
3055+
self.auto_scale_xyz(*viewlim, False)
3056+
3057+
return bars
3058+
29463059
def set_title(self, label, fontdict=None, loc='center', **kwargs):
29473060
# docstring inherited
29483061
ret = super().set_title(label, fontdict=fontdict, loc=loc, **kwargs)

0 commit comments

Comments
 (0)