Skip to content

Commit ea0a0ee

Browse files
Azaya89maximlt
andauthored
Complete the signature of plot methods with all their kind options (#1523)
Co-authored-by: maximlt <mliquet@anaconda.com>
1 parent e09f678 commit ea0a0ee

File tree

1 file changed

+98
-34
lines changed

1 file changed

+98
-34
lines changed

hvplot/plotting/core.py

Lines changed: 98 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ def ohlc(self, x=None, y=None, **kwds):
799799
"""
800800
return self(kind='ohlc', x=x, y=y, **kwds)
801801

802-
def heatmap(self, x=None, y=None, C=None, colorbar=True, **kwds):
802+
def heatmap(self, x=None, y=None, C=None, colorbar=True, logz=False, **kwds):
803803
"""
804804
`heatmap` visualises tabular data indexed by two key dimensions as a grid of colored values.
805805
This allows spotting correlations in multivariate data and provides a high-level overview
@@ -822,6 +822,7 @@ def heatmap(self, x=None, y=None, C=None, colorbar=True, **kwds):
822822
Whether to apply log scaling to the z-axis. Default is False.
823823
reduce_function : function, optional
824824
Function to compute statistics for heatmap, for example `np.mean`.
825+
If omitted, no aggregation is applied and duplicate values are dropped.
825826
**kwds : optional
826827
Additional keywords arguments are documented in `hvplot.help('heatmap')`.
827828
@@ -860,9 +861,19 @@ def heatmap(self, x=None, y=None, C=None, colorbar=True, **kwds):
860861
- Plotly: https://plotly.com/python/heatmaps/
861862
- Wiki: https://en.wikipedia.org/wiki/Heat_map
862863
"""
863-
return self(x, y, kind='heatmap', C=C, colorbar=colorbar, **kwds)
864-
865-
def hexbin(self, x=None, y=None, C=None, colorbar=True, **kwds):
864+
return self(x, y, kind='heatmap', C=C, colorbar=colorbar, logz=logz, **kwds)
865+
866+
def hexbin(
867+
self,
868+
x=None,
869+
y=None,
870+
C=None,
871+
colorbar=True,
872+
gridsize=50,
873+
logz=False,
874+
min_count=None,
875+
**kwds,
876+
):
866877
"""
867878
The `hexbin` plot uses hexagons to split the area into several parts and attribute a color
868879
to it.
@@ -883,8 +894,12 @@ def hexbin(self, x=None, y=None, C=None, colorbar=True, **kwds):
883894
Whether to display a colorbar. Default is True.
884895
reduce_function : function, optional
885896
Function to compute statistics for hexbins, for example `np.mean`.
886-
gridsize: int, optional
887-
The number of hexagons in the x-direction
897+
Default aggregation is a count of the values in the area.
898+
gridsize: int or tuple, optional
899+
Number of hexagonal bins along x- and y-axes. Defaults to uniform
900+
sampling along both axes when setting and integer but independent
901+
bin sampling can be specified a tuple of integers corresponding to
902+
the number of bins along each axis. Default is 50.
888903
logz : bool
889904
Whether to apply log scaling to the z-axis. Default is False.
890905
min_count : number, optional
@@ -928,9 +943,21 @@ def hexbin(self, x=None, y=None, C=None, colorbar=True, **kwds):
928943
- Plotly: https://plotly.com/python/hexbin-mapbox/
929944
- Wiki: https://think.design/services/data-visualization-data-design/hexbin/
930945
"""
931-
return self(x, y, kind='hexbin', C=C, colorbar=colorbar, **kwds)
946+
return self(
947+
x,
948+
y,
949+
kind='hexbin',
950+
C=C,
951+
colorbar=colorbar,
952+
gridsize=gridsize,
953+
logz=logz,
954+
min_count=min_count,
955+
**kwds,
956+
)
932957

933-
def bivariate(self, x=None, y=None, colorbar=True, **kwds):
958+
def bivariate(
959+
self, x=None, y=None, colorbar=True, bandwidth=None, cut=3, filled=False, levels=10, **kwds
960+
):
934961
"""
935962
A bivariate, density plot uses nested contours (or contours plus colors) to indicate
936963
regions of higher local density.
@@ -950,12 +977,13 @@ def bivariate(self, x=None, y=None, colorbar=True, **kwds):
950977
Whether to display a colorbar
951978
bandwidth: int, optional
952979
The bandwidth of the kernel for the density estimate. Default is None.
953-
cut: Integer, Optional
954-
Draw the estimate to cut * bw from the extreme data points. Default is None.
980+
cut: int, optional
981+
Draw the estimate to cut * bw from the extreme data points. Default is 3.
955982
filled : bool, optional
956-
If True the the contours will be filled. Default is False.
957-
levels: int, optional
958-
The number of contour lines to draw. Default is 10.
983+
If True the contours will be filled. Default is False.
984+
levels: int or list, optional
985+
The number of contour lines to draw or a list of scalar values used
986+
to specify the contour levels. Default is 10.
959987
960988
**kwds : optional
961989
Additional keywords arguments are documented in `hvplot.help('bivariate')`.
@@ -1000,7 +1028,17 @@ def bivariate(self, x=None, y=None, colorbar=True, **kwds):
10001028
- Seaborn: https://seaborn.pydata.org/generated/seaborn.kdeplot.html
10011029
- Wiki: https://en.wikipedia.org/wiki/Bivariate_analysis
10021030
"""
1003-
return self(x, y, kind='bivariate', colorbar=colorbar, **kwds)
1031+
return self(
1032+
x,
1033+
y,
1034+
kind='bivariate',
1035+
colorbar=colorbar,
1036+
bandwidth=bandwidth,
1037+
cut=cut,
1038+
filled=filled,
1039+
levels=levels,
1040+
**kwds,
1041+
)
10041042

10051043
def bar(self, x=None, y=None, stacked=False, **kwds):
10061044
"""
@@ -1289,7 +1327,9 @@ def violin(self, y=None, by=None, **kwds):
12891327
"""
12901328
return self(kind='violin', x=None, y=y, by=by, **dict(kwds, hover=False))
12911329

1292-
def hist(self, y=None, by=None, **kwds):
1330+
def hist(
1331+
self, y=None, by=None, bins=20, bin_range=None, normed=False, cumulative=False, **kwds
1332+
):
12931333
"""
12941334
A `histogram` displays an approximate representation of the distribution of continuous data.
12951335
@@ -1302,18 +1342,25 @@ def hist(self, y=None, by=None, **kwds):
13021342
Please note the fields should contain continuous data. Not categorical.
13031343
by : string or sequence
13041344
Field(s) in the *long* data to group by.
1305-
bins : int, optional
1306-
The number of bins
1345+
bins : int or string or np.ndarray or list or tuple, optional
1346+
The number of bins in the histogram, or an explicit set of bin edges
1347+
or a method to find the optimal set of bin edges, e.g. 'auto', 'fd',
1348+
'scott' etc. For more documentation on these approaches see the
1349+
:class:`numpy:numpy.histogram_bin_edges` documentation. Default is 20.
13071350
bin_range: tuple, optional
1308-
The lower and upper range of the bins. Default is None.
1309-
normed : bool, optional
1310-
If True the distribution will sum to 1. Default is False.
1311-
cumulative: bool, optional
1312-
If True, then a histogram is computed where each bin gives the counts in that bin plus
1313-
all bins for smaller values. The last bin gives the total number of datapoints.
1351+
The lower and upper range of the bins.
1352+
Default is the minimum and maximum values of the continuous data.
1353+
normed : str or bool, optional
1354+
Controls normalization behavior. If ``True`` or ``'integral'``, then
1355+
``density=True`` is passed to np.histogram, and the distribution
1356+
is normalized such that the integral is unity. If ``False``,
1357+
then the frequencies will be raw counts. If ``'height'``, then the
1358+
frequencies are normalized such that the max bin height is unity.
13141359
Default is False.
1315-
alpha : float, optional
1316-
An alpha value between 0.0 and 1.0 to better visualize multiple fields. Default is 1.0.
1360+
cumulative: bool, optional
1361+
If True, then a histogram is computed where each bin gives the counts
1362+
in that bin plus all bins for smaller values. The last bin gives the
1363+
total number of data points. Default is False.
13171364
kwds : optional
13181365
Additional keywords arguments are documented in `hvplot.help('hist')`.
13191366
@@ -1368,7 +1415,16 @@ def hist(self, y=None, by=None, **kwds):
13681415
- Seaborn: https://seaborn.pydata.org/generated/seaborn.histplot.html
13691416
- Wiki: https://en.wikipedia.org/wiki/Histogram
13701417
"""
1371-
return self(kind='hist', x=None, y=y, by=by, **kwds)
1418+
return self(
1419+
kind='hist',
1420+
x=None,
1421+
y=y,
1422+
by=by,
1423+
bins=bins,
1424+
normed=normed,
1425+
cumulative=cumulative,
1426+
**kwds,
1427+
)
13721428

13731429
def kde(self, y=None, by=None, **kwds):
13741430
"""
@@ -2252,7 +2308,7 @@ def quadmesh(self, x=None, y=None, z=None, colorbar=True, **kwds):
22522308
"""
22532309
return self(x, y, z=z, kind='quadmesh', colorbar=colorbar, **kwds)
22542310

2255-
def contour(self, x=None, y=None, z=None, colorbar=True, **kwds):
2311+
def contour(self, x=None, y=None, z=None, colorbar=True, levels=5, logz=False, **kwds):
22562312
"""
22572313
Line contour plot
22582314
@@ -2266,10 +2322,13 @@ def contour(self, x=None, y=None, z=None, colorbar=True, **kwds):
22662322
The coordinate variable along the y-axis
22672323
z : string, optional
22682324
The data variable to plot
2269-
levels: int, optional
2270-
The number of contour levels
22712325
colorbar: boolean
22722326
Whether to display a colorbar
2327+
levels: int or list, optional
2328+
The number of contour lines to draw or a list of scalar values used
2329+
to specify the contour levels. Default is 5
2330+
logz: bool, optional
2331+
Whether to apply log scaling to the z-axis. Default is False
22732332
**kwds : optional
22742333
Additional keywords arguments are documented in `hvplot.help('contour')`.
22752334
@@ -2313,9 +2372,9 @@ def contour(self, x=None, y=None, z=None, colorbar=True, **kwds):
23132372
- Matplotlib: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.contour.html
23142373
- Plotly: https://plotly.com/python/contour-plots/
23152374
"""
2316-
return self(x, y, z=z, kind='contour', colorbar=colorbar, **kwds)
2375+
return self(x, y, z=z, kind='contour', colorbar=colorbar, levels=levels, logz=logz, **kwds)
23172376

2318-
def contourf(self, x=None, y=None, z=None, colorbar=True, **kwds):
2377+
def contourf(self, x=None, y=None, z=None, colorbar=True, levels=5, logz=False, **kwds):
23192378
"""
23202379
Filled contour plot
23212380
@@ -2329,10 +2388,13 @@ def contourf(self, x=None, y=None, z=None, colorbar=True, **kwds):
23292388
The coordinate variable along the y-axis
23302389
z : string, optional
23312390
The data variable to plot
2332-
levels: int, optional
2333-
The number of contour levels
23342391
colorbar: boolean
23352392
Whether to display a colorbar
2393+
levels: int, optional
2394+
The number of contour lines to draw or a list of scalar values used
2395+
to specify the contour levels. Default is 5
2396+
logz: bool, optional
2397+
Whether to apply log scaling to the z-axis. Default is False
23362398
**kwds : optional
23372399
Additional keywords arguments are documented in `hvplot.help('contourf')`.
23382400
@@ -2375,4 +2437,6 @@ def contourf(self, x=None, y=None, z=None, colorbar=True, **kwds):
23752437
- Matplotlib: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.contour.html
23762438
- Plotly: https://plotly.com/python/contour-plots/
23772439
"""
2378-
return self(x, y, z=z, kind='contourf', colorbar=colorbar, **kwds)
2440+
return self(
2441+
x, y, z=z, kind='contourf', colorbar=colorbar, levels=levels, logz=logz, **kwds
2442+
)

0 commit comments

Comments
 (0)