hvplot 0.9.3a1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. hvplot/__init__.py +322 -0
  2. hvplot/_version.py +16 -0
  3. hvplot/backend_transforms.py +329 -0
  4. hvplot/converter.py +2855 -0
  5. hvplot/cudf.py +26 -0
  6. hvplot/dask.py +42 -0
  7. hvplot/data/crime.csv +56 -0
  8. hvplot/datasets.yaml +48 -0
  9. hvplot/fugue.py +64 -0
  10. hvplot/ibis.py +21 -0
  11. hvplot/intake.py +32 -0
  12. hvplot/interactive.py +968 -0
  13. hvplot/networkx.py +625 -0
  14. hvplot/pandas.py +30 -0
  15. hvplot/plotting/__init__.py +63 -0
  16. hvplot/plotting/andrews_curves.py +99 -0
  17. hvplot/plotting/core.py +2288 -0
  18. hvplot/plotting/lag_plot.py +34 -0
  19. hvplot/plotting/parallel_coordinates.py +85 -0
  20. hvplot/plotting/scatter_matrix.py +220 -0
  21. hvplot/polars.py +21 -0
  22. hvplot/sample_data.py +30 -0
  23. hvplot/streamz.py +21 -0
  24. hvplot/tests/__init__.py +0 -0
  25. hvplot/tests/conftest.py +44 -0
  26. hvplot/tests/data/README.md +5 -0
  27. hvplot/tests/data/RGB-red.byte.tif +0 -0
  28. hvplot/tests/plotting/__init__.py +0 -0
  29. hvplot/tests/plotting/testcore.py +108 -0
  30. hvplot/tests/plotting/testohlc.py +34 -0
  31. hvplot/tests/plotting/testscattermatrix.py +138 -0
  32. hvplot/tests/test_links.py +99 -0
  33. hvplot/tests/testbackend_transforms.py +89 -0
  34. hvplot/tests/testcharts.py +452 -0
  35. hvplot/tests/testfugue.py +46 -0
  36. hvplot/tests/testgeo.py +468 -0
  37. hvplot/tests/testgeowithoutgv.py +60 -0
  38. hvplot/tests/testgridplots.py +259 -0
  39. hvplot/tests/testhelp.py +75 -0
  40. hvplot/tests/testibis.py +17 -0
  41. hvplot/tests/testinteractive.py +1442 -0
  42. hvplot/tests/testnetworkx.py +26 -0
  43. hvplot/tests/testoperations.py +385 -0
  44. hvplot/tests/testoptions.py +596 -0
  45. hvplot/tests/testoverrides.py +74 -0
  46. hvplot/tests/testpanel.py +70 -0
  47. hvplot/tests/testpatch.py +135 -0
  48. hvplot/tests/testplotting.py +69 -0
  49. hvplot/tests/teststreaming.py +28 -0
  50. hvplot/tests/testtransforms.py +39 -0
  51. hvplot/tests/testui.py +383 -0
  52. hvplot/tests/testutil.py +378 -0
  53. hvplot/tests/util.py +82 -0
  54. hvplot/ui.py +1032 -0
  55. hvplot/util.py +677 -0
  56. hvplot/utilities.py +129 -0
  57. hvplot/xarray.py +62 -0
  58. hvplot-0.9.3a1.dist-info/LICENSE +29 -0
  59. hvplot-0.9.3a1.dist-info/METADATA +243 -0
  60. hvplot-0.9.3a1.dist-info/RECORD +63 -0
  61. hvplot-0.9.3a1.dist-info/WHEEL +5 -0
  62. hvplot-0.9.3a1.dist-info/entry_points.txt +2 -0
  63. hvplot-0.9.3a1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,2288 @@
1
+ import itertools
2
+ from collections import defaultdict
3
+
4
+ import param
5
+
6
+ try:
7
+ import panel as pn
8
+
9
+ panel_available = True
10
+ except ImportError:
11
+ panel_available = False
12
+
13
+ from ..converter import HoloViewsConverter
14
+ from ..util import is_list_like, process_dynamic_args
15
+
16
+ # Color palette for examples: https://www.color-hex.com/color-palette/1018056
17
+ # light green: #55a194
18
+ # Dark green: #3b7067
19
+ # Blue: #1e85f7
20
+ # Orange: #f8b014
21
+ # Red: #f16a6f
22
+
23
+
24
+ class hvPlotBase:
25
+ """
26
+ Internal base class.
27
+
28
+ Concrete subclasses must implement plotting methods (e.g. `line`, `scatter`, `image`).
29
+ A plotting method must call `self` which will effectively create a HoloViewsConverter
30
+ and call it to return a HoloViews object.
31
+
32
+ Concrete subclasses are meant to be mounted onto a datastructure property, e.g.:
33
+
34
+ ```
35
+ _patch_plot = lambda self: hvPlotTabular(self)
36
+ _patch_plot.__doc__ = hvPlotTabular.__call__.__doc__
37
+ plot_prop = property(_patch_plot)
38
+ setattr(pd.DataFrame, 'hvplot', plot_prop)
39
+ ```
40
+ """
41
+
42
+ __all__ = []
43
+
44
+ def __init__(self, data, custom_plots={}, **metadata):
45
+ if 'query' in metadata:
46
+ data = data.query(metadata.pop('query'))
47
+ if 'sel' in metadata:
48
+ data = data.sel(**metadata.pop('sel'))
49
+ if 'isel' in metadata:
50
+ data = data.isel(**metadata.pop('isel'))
51
+ self._data = data
52
+ self._plots = custom_plots
53
+ self._metadata = metadata
54
+
55
+ def __call__(self, x=None, y=None, kind=None, **kwds):
56
+ # Convert an array-like to a list
57
+ x = list(x) if is_list_like(x) else x
58
+ y = list(y) if is_list_like(y) else y
59
+
60
+ if isinstance(kind, str) and kind not in self.__all__:
61
+ raise NotImplementedError(f"kind='{kind}' for data of type {type(self._data)}")
62
+
63
+ if isinstance(kind, str) and kind == 'explorer':
64
+ return self.explorer(x=x, y=y, **kwds)
65
+
66
+ if panel_available:
67
+ panel_args = ['widgets', 'widget_location', 'widget_layout', 'widget_type']
68
+ panel_dict = {}
69
+ for k in panel_args:
70
+ if k in kwds:
71
+ panel_dict[k] = kwds.pop(k)
72
+ dynamic, arg_deps, arg_names = process_dynamic_args(x, y, kind, **kwds)
73
+ if dynamic or arg_deps:
74
+
75
+ @pn.depends(*arg_deps, **dynamic)
76
+ def callback(*args, **dyn_kwds):
77
+ xd = dyn_kwds.pop('x', x)
78
+ yd = dyn_kwds.pop('y', y)
79
+ kindd = dyn_kwds.pop('kind', kind)
80
+
81
+ combined_kwds = dict(kwds, **dyn_kwds)
82
+ fn_args = defaultdict(list)
83
+ for name, arg in zip(arg_names, args):
84
+ fn_args[(name, kwds[name])].append(arg)
85
+ for (name, fn), args in fn_args.items():
86
+ combined_kwds[name] = fn(*args)
87
+ plot = self._get_converter(xd, yd, kindd, **combined_kwds)(kindd, xd, yd)
88
+ return pn.panel(plot, **panel_dict)
89
+
90
+ return pn.panel(callback)
91
+ if panel_dict:
92
+ plot = self._get_converter(x, y, kind, **kwds)(kind, x, y)
93
+ return pn.panel(plot, **panel_dict)
94
+
95
+ return self._get_converter(x, y, kind, **kwds)(kind, x, y)
96
+
97
+ def _get_converter(self, x=None, y=None, kind=None, **kwds):
98
+ params = dict(self._metadata, **kwds)
99
+ x = x or params.pop('x', None)
100
+ y = y or params.pop('y', None)
101
+ kind = kind or params.pop('kind', None)
102
+ return HoloViewsConverter(self._data, x, y, kind=kind, **params)
103
+
104
+ def __dir__(self):
105
+ """
106
+ List default attributes and custom defined plots.
107
+ """
108
+ dirs = super().__dir__()
109
+ return sorted(list(dirs) + list(self._plots))
110
+
111
+ def __getattribute__(self, name):
112
+ """
113
+ Custom getattribute to expose user defined subplots.
114
+ """
115
+ plots = object.__getattribute__(self, '_plots')
116
+ if name in plots:
117
+ plot_opts = plots[name]
118
+ if 'kind' in plot_opts and name in HoloViewsConverter._kind_mapping:
119
+ param.main.param.warning(
120
+ 'Custom options for existing plot types should not '
121
+ "declare the 'kind' argument. The .{} plot method "
122
+ 'was unexpectedly customized with kind={!r}.'.format(plot_opts['kind'], name)
123
+ )
124
+ plot_opts['kind'] = name
125
+ return hvPlotBase(self._data, **dict(self._metadata, **plot_opts))
126
+ return super().__getattribute__(name)
127
+
128
+ def explorer(self, x=None, y=None, **kwds):
129
+ """
130
+ The `explorer` plot allows you to interactively explore your data.
131
+
132
+ Reference: https://hvplot.holoviz.org/user_guide/Explorer.html
133
+
134
+ Parameters
135
+ ----------
136
+ x : string, optional
137
+ The coordinate variable along the x-axis
138
+ y : string, optional
139
+ The coordinate variable along the y-axis
140
+ **kwds : optional
141
+ Additional keywords arguments typically passed to hvplot's call.
142
+
143
+ Returns
144
+ -------
145
+ The corresponding explorer type based on data, e.g. hvplot.ui.hvDataFrameExplorer.
146
+
147
+ Examples
148
+ --------
149
+
150
+ .. code-block:
151
+
152
+ import hvplot.pandas
153
+ import pandas as pd
154
+
155
+ df = pd.DataFrame(
156
+ {
157
+ "actual": [100, 150, 125, 140, 145, 135, 123],
158
+ "forecast": [90, 160, 125, 150, 141, 141, 120],
159
+ "numerical": [1.1, 1.9, 3.2, 3.8, 4.3, 5.0, 5.5],
160
+ "date": pd.date_range("2022-01-03", "2022-01-09"),
161
+ "string": ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
162
+ },
163
+ )
164
+ df.hvplot.explorer()
165
+ """
166
+ from ..ui import explorer as ui_explorer
167
+
168
+ return ui_explorer(self._data, x=x, y=y, **kwds)
169
+
170
+
171
+ class hvPlotTabular(hvPlotBase):
172
+ """
173
+ The plotting method: `df.hvplot(...)` creates a plot similarly to the familiar Pandas
174
+ `df.plot` method.
175
+
176
+ For more detailed options use a specific plotting method, e.g. `df.hvplot.line`.
177
+
178
+ Reference: https://hvplot.holoviz.org/reference/index.html
179
+
180
+ Parameters
181
+ ----------
182
+ x : string, optional
183
+ Field name(s) to draw x-positions from. If not specified, the index is
184
+ used.
185
+ y : string or list, optional
186
+ Field name(s) to draw y-positions from. If not specified, all numerical
187
+ fields are used.
188
+ kind : string, optional
189
+ The kind of plot to generate, e.g. 'area', 'bar', 'line', 'scatter' etc. To see the
190
+ available plots run `print(df.hvplot.__all__)`.
191
+ **kwds : optional
192
+ Additional keywords arguments are documented in `hvplot.help('scatter')` or similar
193
+ depending on the kind of plot.
194
+
195
+ Returns
196
+ -------
197
+ A Holoviews object. You can `print` the object to study its composition and run
198
+
199
+ .. code-block::
200
+
201
+ import holoviews as hv
202
+ hv.help(the_holoviews_object)
203
+
204
+ to learn more about its parameters and options.
205
+
206
+ Examples
207
+ --------
208
+
209
+ .. code-block::
210
+
211
+ import pandas as pd
212
+ import hvplot.pandas
213
+
214
+ df = pd.DataFrame(
215
+ {
216
+ "actual": [100, 150, 125, 140, 145, 135, 123],
217
+ "forecast": [90, 160, 125, 150, 141, 141, 120],
218
+ "numerical": [1.1, 1.9, 3.2, 3.8, 4.3, 5.0, 5.5],
219
+ "date": pd.date_range("2022-01-03", "2022-01-09"),
220
+ "string": ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
221
+ },
222
+ )
223
+ line = df.hvplot.line(
224
+ x="numerical",
225
+ y=["actual", "forecast"],
226
+ ylabel="value",
227
+ legend="bottom",
228
+ height=500,
229
+ color=["steelblue", "teal"],
230
+ alpha=0.7,
231
+ line_width=5,
232
+ )
233
+ line
234
+
235
+ You can can add *markers* to a `line` plot by overlaying with a `scatter` plot.
236
+
237
+ .. code-block::
238
+
239
+ markers = df.hvplot.scatter(
240
+ x="numerical", y=["actual", "forecast"], color=["#f16a6f", "#1e85f7"], size=50
241
+ )
242
+ line * markers
243
+
244
+ Please note that you can pass widgets or reactive functions as arguments instead of
245
+ literal values, c.f. https://hvplot.holoviz.org/user_guide/Widgets.html.
246
+ """
247
+
248
+ __all__ = [
249
+ 'line',
250
+ 'step',
251
+ 'scatter',
252
+ 'area',
253
+ 'errorbars',
254
+ 'ohlc',
255
+ 'heatmap',
256
+ 'hexbin',
257
+ 'bivariate',
258
+ 'bar',
259
+ 'barh',
260
+ 'box',
261
+ 'violin',
262
+ 'hist',
263
+ 'kde',
264
+ 'density',
265
+ 'table',
266
+ 'dataset',
267
+ 'points',
268
+ 'vectorfield',
269
+ 'polygons',
270
+ 'paths',
271
+ 'labels',
272
+ 'explorer',
273
+ ]
274
+
275
+ def line(self, x=None, y=None, **kwds):
276
+ """
277
+ The `line` plot connects the points with a continuous curve.
278
+
279
+ Reference: https://hvplot.holoviz.org/reference/tabular/line.html
280
+
281
+ Parameters
282
+ ----------
283
+ x : string, optional
284
+ Field name(s) to draw x-positions from. If not specified, the index is
285
+ used. Can refer to continuous and categorical data.
286
+ y : string or list, optional
287
+ Field name(s) to draw y-positions from. If not specified, all numerical
288
+ fields are used.
289
+ by : string, optional
290
+ A single column or list of columns to group by. All the subgroups are visualized.
291
+ groupby: string, list, optional
292
+ A single field or list of fields to group and filter by. Adds one or more widgets to
293
+ select the subgroup(s) to visualize.
294
+ color : str or array-like, optional.
295
+ The color for each of the series. Possible values are:
296
+
297
+ A single color string referred to by name, RGB or RGBA code, for instance 'red' or
298
+ '#a98d19.
299
+
300
+ A sequence of color strings referred to by name, RGB or RGBA code, which will be used
301
+ for each series recursively. For instance ['green','yellow'] each field’s line will be
302
+ filled in green or yellow, alternatively. If there is only a single series to be
303
+ plotted, then only the first color from the color list will be used.
304
+ **kwds : optional
305
+ Additional keywords arguments are documented in `hvplot.help('line')`.
306
+
307
+ Returns
308
+ -------
309
+ A Holoviews object. You can `print` the object to study its composition and run
310
+
311
+ .. code-block::
312
+
313
+ import holoviews as hv
314
+ hv.help(the_holoviews_object)
315
+
316
+ to learn more about its parameters and options.
317
+
318
+ Examples
319
+ --------
320
+
321
+ .. code-block::
322
+
323
+ import hvplot.pandas
324
+ import pandas as pd
325
+
326
+ df = pd.DataFrame(
327
+ {
328
+ "actual": [100, 150, 125, 140, 145, 135, 123],
329
+ "forecast": [90, 160, 125, 150, 141, 141, 120],
330
+ "numerical": [1.1, 1.9, 3.2, 3.8, 4.3, 5.0, 5.5],
331
+ "date": pd.date_range("2022-01-03", "2022-01-09"),
332
+ "string": ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
333
+ },
334
+ )
335
+ line = df.hvplot.line(
336
+ x="numerical",
337
+ y=["actual", "forecast"],
338
+ ylabel="value",
339
+ legend="bottom",
340
+ height=500,
341
+ color=["steelblue", "teal"],
342
+ alpha=0.7,
343
+ line_width=5,
344
+ )
345
+ line
346
+
347
+ You can can add *markers* to a `line` plot by overlaying with a `scatter` plot.
348
+
349
+ .. code-block::
350
+
351
+ markers = df.hvplot.scatter(
352
+ x="numerical", y=["actual", "forecast"], color=["steelblue", "teal"], size=50
353
+ )
354
+ line * markers
355
+
356
+ Please note that you can pass widgets or reactive functions as arguments instead of
357
+ literal values, c.f. https://hvplot.holoviz.org/user_guide/Widgets.html.
358
+
359
+ References
360
+ ----------
361
+
362
+ - Bokeh: https://docs.bokeh.org/en/latest/docs/reference/models/glyphs/line.html
363
+ - HoloViews: https://holoviews.org/reference/elements/bokeh/Curve.html
364
+ - Pandas: https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.plot.line.html
365
+ - Plotly: https://plotly.com/python/line-charts/
366
+ - Matplotlib: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html
367
+ - Seaborn: https://seaborn.pydata.org/generated/seaborn.lineplot.html
368
+ - Wiki: https://en.wikipedia.org/wiki/Line_chart
369
+ """
370
+ return self(x, y, kind='line', **kwds)
371
+
372
+ def step(self, x=None, y=None, where='mid', **kwds):
373
+ """
374
+ The `step` plot connects the points with piece-wise constant curves.
375
+
376
+ The `step` plot can be used pretty much anytime the `line` plot might be used, and has many
377
+ of the same options available.
378
+
379
+ Reference: https://hvplot.holoviz.org/reference/tabular/step.html
380
+
381
+ Parameters
382
+ ----------
383
+ x : string, optional
384
+ Field name(s) to draw x-positions from. If not specified, the index is
385
+ used. Must refer to continuous data. Not categorical data.
386
+ y : string or list, optional
387
+ Field name(s) to draw y-positions from. If not specified, all numerical
388
+ fields are used.
389
+ by : string, optional
390
+ A single field or list of fields to group by. All the subgroups are visualized.
391
+ groupby: string, list, optional
392
+ A single field or list of fields to group and filter by. Adds one or more widgets to
393
+ select the subgroup(s) to visualize.
394
+ where: string, optional
395
+ The interpolation method. One of 'mid', 'pre', 'post'. Default is 'mid'.
396
+ color : str or array-like, optional.
397
+ The color for each of the series. Possible values are:
398
+
399
+ A single color string referred to by name, RGB or RGBA code, for instance 'red' or
400
+ '#a98d19.
401
+
402
+ A sequence of color strings referred to by name, RGB or RGBA code, which will be used
403
+ for each series recursively. For instance ['green','yellow'] each field’s line will be
404
+ filled in green or yellow, alternatively. If there is only a single series to be
405
+ plotted, then only the first color from the color list will be used.
406
+ **kwds : optional
407
+ Additional keywords arguments are documented in `hvplot.help('step')`.
408
+
409
+ Returns
410
+ -------
411
+ A Holoviews object. You can `print` the object to study its composition and run
412
+
413
+ .. code-block::
414
+
415
+ import holoviews as hv
416
+ hv.help(the_holoviews_object)
417
+
418
+ to learn more about its parameters and options.
419
+
420
+ Examples
421
+ --------
422
+
423
+ .. code-block::
424
+
425
+ import hvplot.pandas
426
+ import pandas as pd
427
+
428
+ df = pd.DataFrame(
429
+ {
430
+ "actual": [100, 150, 125, 140, 145, 135, 123],
431
+ "forecast": [90, 160, 125, 150, 141, 141, 120],
432
+ "numerical": [1.1, 1.9, 3.2, 3.8, 4.3, 5.0, 5.5],
433
+ "date": pd.date_range("2022-01-03", "2022-01-09"),
434
+ "string": ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
435
+ },
436
+ )
437
+ step = df.hvplot.step(
438
+ x="numerical",
439
+ y=["actual", "forecast"],
440
+ ylabel="value",
441
+ legend="bottom",
442
+ height=500,
443
+ color=["#f16a6f", "#1e85f7"],
444
+ line_width=5,
445
+ )
446
+ step
447
+
448
+ You can can add *markers* to a `step` plot by overlaying with a `scatter` plot.
449
+
450
+ .. code-block::
451
+
452
+ markers = df.hvplot.scatter(
453
+ x="numerical", y=["actual", "forecast"], color=["#f16a6f", "#1e85f7"], size=100
454
+ )
455
+ step * markers
456
+
457
+ Please note that you can pass widgets or reactive functions as arguments instead of
458
+ literal values, c.f. https://hvplot.holoviz.org/user_guide/Widgets.html.
459
+
460
+ References
461
+ ----------
462
+
463
+ - Bokeh: https://docs.bokeh.org/en/latest/docs/reference/models/glyphs/step.html
464
+ - HoloViews: https://holoviews.org/gallery/demos/bokeh/step_chart.html
465
+ - Pandas: https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.plot.line.html (use `draw_style='step')
466
+ - Plotly: https://plotly.com/python/line-charts/ (See the Interpolation Section)
467
+ - Matplotlib: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.step.html
468
+ """
469
+ return self(x, y, kind='step', where=where, **kwds)
470
+
471
+ def scatter(self, x=None, y=None, **kwds):
472
+ """
473
+ The `scatter` plot visualizes your points as markers in 2D space. You can visualize
474
+ one more dimension by using colors.
475
+
476
+ The `scatter` plot is a good first way to plot data with non continuous axes.
477
+
478
+ Reference: https://hvplot.holoviz.org/reference/tabular/scatter.html
479
+
480
+ Parameters
481
+ ----------
482
+ x : string, optional
483
+ Field name(s) to draw x-positions from. If not specified, the index is
484
+ used. Can refer to continuous and categorical data.
485
+ y : string or list, optional
486
+ Field name(s) to draw y-positions from. If not specified, all numerical
487
+ fields are used.
488
+ marker : string, optional
489
+ The marker shape specified above can be any supported by matplotlib, e.g. s, d, o etc.
490
+ See https://matplotlib.org/stable/api/markers_api.html.
491
+ c : string, optional
492
+ A color or a Field name to draw the color of the marker from
493
+ s : int, optional, also available as 'size'
494
+ The size of the marker
495
+ by : string, optional
496
+ A single field or list of fields to group by. All the subgroups are visualized.
497
+ groupby: string, list, optional
498
+ A single field or list of fields to group and filter by. Adds one or more widgets to
499
+ select the subgroup(s) to visualize.
500
+ scale: number, optional
501
+ Scaling factor to apply to point scaling.
502
+ logz : bool
503
+ Whether to apply log scaling to the z-axis. Default is False.
504
+ color : str or array-like, optional.
505
+ The color for each of the series. Possible values are:
506
+
507
+ A single color string referred to by name, RGB or RGBA code, for instance 'red' or
508
+ '#a98d19.
509
+
510
+ A sequence of color strings referred to by name, RGB or RGBA code, which will be used
511
+ for each series recursively. For instance ['green','yellow'] each field’s line will be
512
+ filled in green or yellow, alternatively. If there is only a single series to be
513
+ plotted, then only the first color from the color list will be used.
514
+ **kwds : optional
515
+ Additional keywords arguments are documented in `hvplot.help('scatter')`.
516
+
517
+ Returns
518
+ -------
519
+ A Holoviews object. You can `print` the object to study its composition and run
520
+
521
+ .. code-block::
522
+
523
+ import holoviews as hv
524
+ hv.help(the_holoviews_object)
525
+
526
+ to learn more about its parameters and options.
527
+
528
+ Example
529
+ -------
530
+
531
+ .. code-block::
532
+
533
+ import hvplot.pandas
534
+ import pandas as pd
535
+
536
+ df = pd.DataFrame(
537
+ {
538
+ "actual": [100, 150, 125, 140, 145, 135, 123],
539
+ "forecast": [90, 160, 125, 150, 141, 141, 120],
540
+ "numerical": [1.1, 1.9, 3.2, 3.8, 4.3, 5.0, 5.5],
541
+ "date": pd.date_range("2022-01-03", "2022-01-09"),
542
+ "string": ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
543
+ },
544
+ )
545
+ scatter = df.hvplot.scatter(
546
+ x="numerical",
547
+ y=["actual", "forecast"],
548
+ ylabel="value",
549
+ legend="bottom",
550
+ height=500,
551
+ color=["#f16a6f", "#1e85f7"],
552
+ size=100,
553
+ )
554
+ scatter
555
+
556
+ You can overlay the `scatter` markers on for example a `line` plot
557
+
558
+ .. code-block::
559
+
560
+ line = df.hvplot.line(
561
+ x="numerical", y=["actual", "forecast"], color=["#f16a6f", "#1e85f7"], line_width=5
562
+ )
563
+ scatter * line
564
+
565
+ References
566
+ ----------
567
+
568
+ - Bokeh: https://docs.bokeh.org/en/latest/docs/user_guide/plotting.html#scatter-markers
569
+ - HoloViews: https://holoviews.org/reference/elements/matplotlib/Scatter.html
570
+ - Pandas: https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.plot.scatter.html
571
+ - Plotly: https://plotly.com/python/line-and-scatter/
572
+ - Matplotlib: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.scatter.html
573
+ - Seaborn: https://seaborn.pydata.org/generated/seaborn.scatterplot.html
574
+ - Wiki: https://en.wikipedia.org/wiki/Scatter_plot
575
+ """
576
+ return self(x, y, kind='scatter', **kwds)
577
+
578
+ def area(self, x=None, y=None, y2=None, stacked=True, **kwds):
579
+ """
580
+ The `area` plot can be used to color the area under a line or to color the space between two
581
+ lines.
582
+
583
+ Reference: https://hvplot.holoviz.org/reference/tabular/area.html
584
+
585
+ Parameters
586
+ ----------
587
+ x : string, optional
588
+ Field name(s) to draw x-positions from. If not specified, the index is
589
+ used. Can refer to continuous and categorical data.
590
+ y : string, optional
591
+ Field name to draw the first y-position from
592
+ y2 : string, optional
593
+ Field name to draw the second y-position from
594
+ stacked : boolean, optional
595
+ Whether to stack multiple areas. Default is False.
596
+ **kwds : optional
597
+ Additional keywords arguments are documented in `hvplot.help('area')`.
598
+
599
+ Returns
600
+ -------
601
+ A Holoviews object. You can `print` the object to study its composition and run
602
+
603
+ .. code-block::
604
+
605
+ import holoviews as hv
606
+ hv.help(the_holoviews_object)
607
+
608
+ to learn more about its parameters and options.
609
+
610
+ Example
611
+ -------
612
+
613
+ .. code-block::
614
+
615
+ import hvplot.pandas
616
+ import pandas as pd
617
+
618
+ df = pd.DataFrame(
619
+ {
620
+ "actual": [100, 150, 125, 140, 145, 135, 123],
621
+ "forecast": [90, 160, 125, 150, 141, 141, 120],
622
+ "numerical": [1.1, 1.9, 3.2, 3.8, 4.3, 5.0, 5.5],
623
+ "date": pd.date_range("2022-01-03", "2022-01-09"),
624
+ "string": ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
625
+ },
626
+ )
627
+ df["min"] = df[["actual", "forecast"]].min(axis=1)
628
+ df["max"] = df[["actual", "forecast"]].max(axis=1)
629
+
630
+ area = df.hvplot.area(
631
+ x="numerical",
632
+ y="min",
633
+ y2="max",
634
+ ylabel="value",
635
+ legend="bottom",
636
+ height=500,
637
+ color=["#55a194"],
638
+ alpha=0.7,
639
+ line_width=2,
640
+ ylim=(0, 200),
641
+ )
642
+ area
643
+
644
+ References
645
+ ----------
646
+
647
+ - Bokeh: https://docs.bokeh.org/en/latest/docs/user_guide/plotting.html#directed-areas
648
+ - HoloViews: https://holoviews.org/reference/elements/matplotlib/Area.html
649
+ - Pandas: https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.plot.area.html
650
+ - Plotly: https://plotly.com/python/filled-area-plots/
651
+ - Matplotlib: https://matplotlib.org/stable/gallery/lines_bars_and_markers/fill_between_demo.html
652
+ - Wiki: https://en.wikipedia.org/wiki/Area_chart
653
+ """
654
+ if 'alpha' not in kwds and not stacked:
655
+ kwds['alpha'] = 0.5
656
+ return self(x, y, y2=y2, kind='area', stacked=stacked, **kwds)
657
+
658
+ def errorbars(self, x=None, y=None, yerr1=None, yerr2=None, **kwds):
659
+ """
660
+ `errorbars` provide a visual indicator for the variability of the plotted data on a graph.
661
+ They are usually overlaid with other plots such as `scatter` , `line` or `bar` plots to
662
+ indicate the variability.
663
+
664
+ Reference: https://hvplot.holoviz.org/reference/tabular/errorbars.html
665
+
666
+ Parameters
667
+ ----------
668
+ x : string, optional
669
+ Field name to draw the x-position from. If not specified, the index is
670
+ used. Can refer to continuous and categorical data.
671
+ y : string, optional
672
+ Field name to draw the y-position from
673
+ yerr1 : string, optional
674
+ Field name to draw symmetric / negative errors from
675
+ yerr2 : string, optional
676
+ Field name to draw positive errors from
677
+ **kwds : optional
678
+ Additional keywords arguments are documented in `hvplot.help('errorbars')`.
679
+
680
+ Returns
681
+ -------
682
+ A Holoviews object. You can `print` the object to study its composition and run
683
+
684
+ .. code-block::
685
+
686
+ import holoviews as hv
687
+ hv.help(the_holoviews_object)
688
+
689
+ to learn more about its parameters and options.
690
+
691
+ Example
692
+ -------
693
+
694
+ .. code-block::
695
+
696
+ import hvplot.pandas
697
+ import pandas as pd
698
+
699
+ df = pd.DataFrame(
700
+ {
701
+ "actual": [100, 150, 125, 140, 145, 135, 123],
702
+ "forecast": [90, 160, 125, 150, 141, 141, 120],
703
+ "numerical": [1.1, 1.9, 3.2, 3.8, 4.3, 5.0, 5.5],
704
+ "date": pd.date_range("2022-01-03", "2022-01-09"),
705
+ "string": ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
706
+ },
707
+ )
708
+ df["min"] = df[["actual", "forecast"]].min(axis=1)
709
+ df["max"] = df[["actual", "forecast"]].max(axis=1)
710
+ df["mean"] = df[["actual", "forecast"]].mean(axis=1)
711
+ df["yerr2"] = df["max"] - df["mean"]
712
+ df["yerr1"] = df["mean"] - df["min"]
713
+
714
+ errorbars = df.hvplot.errorbars(
715
+ x="numerical",
716
+ y="mean",
717
+ yerr1="yerr1",
718
+ yerr2="yerr2",
719
+ legend="bottom",
720
+ height=500,
721
+ alpha=0.5,
722
+ line_width=2,
723
+ )
724
+ errorbars
725
+
726
+ Normally you would overlay the `errorbars` on for example a `scatter` plot.
727
+
728
+ .. code-block::
729
+
730
+ mean = df.hvplot.scatter(x="numerical", y=["mean"], color=["#55a194"], size=50)
731
+ errorbars * mean
732
+
733
+ References
734
+ ----------
735
+
736
+ - Bokeh: https://docs.bokeh.org/en/latest/docs/user_guide/annotations.html#whiskers
737
+ - HoloViews: https://holoviews.org/reference/elements/bokeh/ErrorBars.html
738
+ - Matplotlib: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.errorbar.html
739
+ - Pandas: https://pandas.pydata.org/docs/user_guide/visualization.html#visualization-errorbars
740
+ - Plotly: https://plotly.com/python/error-bars/
741
+ - Wikipedia: https://en.wikipedia.org/wiki/Error_bar
742
+ """
743
+ return self(x, y, kind='errorbars', yerr1=yerr1, yerr2=yerr2, **kwds)
744
+
745
+ def ohlc(self, x=None, y=None, **kwds):
746
+ """
747
+ The `ohlc` plot visualizes the open, high, low and close prices of stocks and other assets.
748
+
749
+ Reference: https://hvplot.holoviz.org/reference/tabular/ohlc.html
750
+
751
+ Parameters
752
+ ----------
753
+ x : string, optional
754
+ Field name to draw x coordinates from. If not specified, the index is used. Normally
755
+ refers to date values.
756
+ y : list or tuple, optional
757
+ Field names of the OHLC fields. Default is ["open", "high", "low", "close"]
758
+ line_color : string, optional
759
+ The line color. Default is black
760
+ pos_color : string, optional
761
+ The color indicating a positive change. Default is green.
762
+ neg_color : string, optional
763
+ The color indicating a negative change. Default is red.
764
+ **kwds : optional
765
+ Additional keywords arguments are documented in `hvplot.help('ohlc')`.
766
+
767
+ Returns
768
+ -------
769
+ A Holoviews object. You can `print` the object to study its composition and run
770
+
771
+ .. code-block::
772
+
773
+ import holoviews as hv
774
+ hv.help(the_holoviews_object)
775
+
776
+ to learn more about its parameters and options.
777
+
778
+ Example
779
+ -------
780
+
781
+ .. code-block::
782
+
783
+ data = pd.DataFrame({
784
+ "open": [100, 101, 102],
785
+ "high": [104, 105, 110],
786
+ "low": [94, 97, 99],
787
+ "close": [101, 99, 103],
788
+ }, index=[pd.Timestamp("2022-08-01"), pd.Timestamp("2022-08-02"), pd.Timestamp("2022-08-03")])
789
+ ohlc = data.hvplot.ohlc(pos_color="#55a194", neg_color="#f16a6f")
790
+ ohlc
791
+
792
+ References
793
+ ----------
794
+
795
+ - Bokeh: https://docs.bokeh.org/en/latest/docs/gallery/candlestick.html
796
+ - Matplotlib: https://www.statology.org/matplotlib-python-candlestick-chart/
797
+ - Plotly: https://plotly.com/python/ohlc-charts/
798
+ - Wikipedia: https://en.wikipedia.org/wiki/Candlestick_chart
799
+ """
800
+ return self(kind='ohlc', x=x, y=y, **kwds)
801
+
802
+ def heatmap(self, x=None, y=None, C=None, colorbar=True, **kwds):
803
+ """
804
+ `heatmap` visualises tabular data indexed by two key dimensions as a grid of colored values.
805
+ This allows spotting correlations in multivariate data and provides a high-level overview
806
+ of how the two variables are plotted.
807
+
808
+ Reference: https://hvplot.holoviz.org/reference/tabular/heatmap.html
809
+
810
+ Parameters
811
+ ----------
812
+ x : string, optional
813
+ Field name to draw x coordinates from. If not specified, the index is used. Can refer
814
+ to continuous and categorical data.
815
+ y : string
816
+ Field name to draw y-positions from. Can refer to continuous and categorical data.
817
+ C : string, optional
818
+ Field to draw heatmap color from. If not specified a simple count will be used.
819
+ colorbar: boolean, optional
820
+ Whether to display a colorbar. Default is True.
821
+ logz : bool
822
+ Whether to apply log scaling to the z-axis. Default is False.
823
+ reduce_function : function, optional
824
+ Function to compute statistics for heatmap, for example `np.mean`.
825
+ **kwds : optional
826
+ Additional keywords arguments are documented in `hvplot.help('heatmap')`.
827
+
828
+ Returns
829
+ -------
830
+ A Holoviews object. You can `print` the object to study its composition and run
831
+
832
+ .. code-block::
833
+
834
+ import holoviews as hv
835
+ hv.help(the_holoviews_object)
836
+
837
+ to learn more about its parameters and options.
838
+
839
+ Example
840
+ -------
841
+
842
+ .. code-block::
843
+
844
+ import hvplot.pandas
845
+ import numpy as np
846
+ from bokeh.sampledata import sea_surface_temperature as sst
847
+
848
+ df = sst.sea_surface_temperature
849
+ df.hvplot.heatmap(
850
+ x="time.month", y="time.day", C="temperature", reduce_function=np.mean,
851
+ height=500, width=500, colorbar=False, cmap="blues"
852
+ )
853
+
854
+ References
855
+ ----------
856
+
857
+ - Bokeh: https://docs.bokeh.org/en/latest/docs/gallery/categorical_heatmap.html
858
+ - HoloViews: https://holoviews.org/reference/elements/bokeh/HeatMap.html
859
+ - Matplotlib: https://matplotlib.org/stable/gallery/images_contours_and_fields/image_annotated_heatmap.html
860
+ - Plotly: https://plotly.com/python/heatmaps/
861
+ - Wiki: https://en.wikipedia.org/wiki/Heat_map
862
+ """
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):
866
+ """
867
+ The `hexbin` plot uses hexagons to split the area into several parts and attribute a color
868
+ to it.
869
+
870
+ `hexbin` offers a straightforward method for plotting dense data.
871
+
872
+ Reference: https://hvplot.holoviz.org/reference/tabular/hexbin.html
873
+
874
+ Parameters
875
+ ----------
876
+ x : string, optional
877
+ Field name to draw x coordinates from. If not specified, the index is used.
878
+ y : string
879
+ Field name to draw y-positions from
880
+ C : string, optional
881
+ Field to draw hexbin color from. If not specified a simple count will be used.
882
+ colorbar: boolean, optional
883
+ Whether to display a colorbar. Default is True.
884
+ reduce_function : function, optional
885
+ Function to compute statistics for hexbins, for example `np.mean`.
886
+ gridsize: int, optional
887
+ The number of hexagons in the x-direction
888
+ logz : bool
889
+ Whether to apply log scaling to the z-axis. Default is False.
890
+ min_count : number, optional
891
+ The display threshold before a bin is shown, by default bins with
892
+ a count of less than 1 are hidden
893
+ **kwds : optional
894
+ Additional keywords arguments are documented in `hvplot.help('hexbin')`.
895
+
896
+ Returns
897
+ -------
898
+ A Holoviews object. You can `print` the object to study its composition and run
899
+
900
+ .. code-block::
901
+
902
+ import holoviews as hv
903
+ hv.help(the_holoviews_object)
904
+
905
+ to learn more about its parameters and options.
906
+
907
+ Example
908
+ -------
909
+
910
+ .. code-block::
911
+
912
+ import hvplot.pandas
913
+ import pandas as pd
914
+ import numpy as np
915
+
916
+ n = 500
917
+ df = pd.DataFrame({
918
+ "x": 2 + 2 * np.random.standard_normal(n),
919
+ "y": 2 + 2 * np.random.standard_normal(n),
920
+ })
921
+ df.hvplot.hexbin("x", "y", clabel="Count", cmap="plasma_r", height=400, width=500)
922
+
923
+ References
924
+ ----------
925
+
926
+ - Bokeh: https://docs.bokeh.org/en/latest/docs/gallery/hexbin.html
927
+ - HoloViews: https://holoviews.org/reference/elements/bokeh/HexTiles.html
928
+ - Plotly: https://plotly.com/python/hexbin-mapbox/
929
+ - Wiki: https://think.design/services/data-visualization-data-design/hexbin/
930
+ """
931
+ return self(x, y, kind='hexbin', C=C, colorbar=colorbar, **kwds)
932
+
933
+ def bivariate(self, x=None, y=None, colorbar=True, **kwds):
934
+ """
935
+ A bivariate, density plot uses nested contours (or contours plus colors) to indicate
936
+ regions of higher local density.
937
+
938
+ `bivariate` plots can be a useful alternative to scatter plots, if your data are too dense
939
+ to plot each point individually.
940
+
941
+ Reference: https://hvplot.holoviz.org/reference/tabular/bivariate.html
942
+
943
+ Parameters
944
+ ----------
945
+ x : string, optional
946
+ Field name to draw x-positions from. If not specified, the index is used.
947
+ y : string, optional
948
+ Field name to draw y-positions from
949
+ colorbar: boolean
950
+ Whether to display a colorbar
951
+ bandwidth: int, optional
952
+ 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.
955
+ 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.
959
+
960
+ **kwds : optional
961
+ Additional keywords arguments are documented in `hvplot.help('bivariate')`.
962
+
963
+ Returns
964
+ -------
965
+ A Holoviews object. You can `print` the object to study its composition and run
966
+
967
+ .. code-block::
968
+
969
+ import holoviews as hv
970
+ hv.help(the_holoviews_object)
971
+
972
+ to learn more about its parameters and options.
973
+
974
+ Examples
975
+ --------
976
+
977
+ .. code-block::
978
+
979
+ import hvplot.pandas
980
+ from bokeh.sampledata.autompg import autompg_clean as df
981
+
982
+ bivariate = df.hvplot.bivariate("accel", "mpg", filled=True, cmap="blues")
983
+ bivariate
984
+
985
+ To get a better intuitive understanding of the `bivariate` plot, you can try overlaying the
986
+ corresponding scatter plot.
987
+
988
+ .. code-block::
989
+
990
+ scatter = df.hvplot.scatter("accel", "mpg")
991
+ bivariate * scatter
992
+
993
+ References
994
+ ----------
995
+
996
+ - ggplot: https://bio304-class.github.io/bio304-fall2017/ggplot-bivariate.html
997
+ - HoloViews: https://holoviews.org/reference/elements/bokeh/Bivariate.html
998
+ - Plotly: https://plotly.com/python/2d-histogram-contour/
999
+ - Matplotlib: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.contour.html
1000
+ - Seaborn: https://seaborn.pydata.org/generated/seaborn.kdeplot.html
1001
+ - Wiki: https://en.wikipedia.org/wiki/Bivariate_analysis
1002
+ """
1003
+ return self(x, y, kind='bivariate', colorbar=colorbar, **kwds)
1004
+
1005
+ def bar(self, x=None, y=None, **kwds):
1006
+ """
1007
+ A vertical bar plot
1008
+
1009
+ A `bar` plot represents categorical data with rectangular bars
1010
+ with heights proportional to the values that they represent. The x-axis
1011
+ represents the categories and the y axis represents the value scale.
1012
+ The bars are of equal width which allows for instant comparison of data.
1013
+
1014
+ Reference: https://hvplot.holoviz.org/reference/tabular/bar.html
1015
+
1016
+ Parameters
1017
+ ----------
1018
+ x : string, optional
1019
+ Field name to draw x-positions from. If not specified, the index is used.
1020
+ y : string, optional
1021
+ Field name to draw y-positions from. If not specified, all numerical
1022
+ fields are used.
1023
+ stacked : bool, optional
1024
+ If True, creates a stacked bar plot. Default is False.
1025
+ color : str or array-like, optional.
1026
+ The color for each of the series. Possible values are:
1027
+
1028
+ The name of the field to draw the colors from. The field can contain numerical values or strings
1029
+ representing colors.
1030
+
1031
+ A single color string referred to by name, RGB or RGBA code, for instance 'red' or
1032
+ '#a98d19'.
1033
+
1034
+ A sequence of color strings referred to by name, RGB or RGBA code, which will be used
1035
+ for each series recursively. For instance ['red', 'green','blue'].
1036
+ **kwds : optional
1037
+ Additional keywords arguments are documented in `hvplot.help('bar')`.
1038
+
1039
+ Returns
1040
+ -------
1041
+ A Holoviews object. You can `print` the object to study its composition and run
1042
+
1043
+ .. code-block::
1044
+
1045
+ import holoviews as hv
1046
+ hv.help(the_holoviews_object)
1047
+
1048
+ to learn more about its parameters and options.
1049
+
1050
+ Example
1051
+ -------
1052
+
1053
+ .. code-block::
1054
+
1055
+ import hvplot.pandas
1056
+ import pandas as pd
1057
+
1058
+ df = pd.DataFrame(
1059
+ {
1060
+ "actual": [100, 150, 125, 140, 145, 135, 123],
1061
+ "forecast": [90, 160, 125, 150, 141, 141, 120],
1062
+ "numerical": [1.1, 1.9, 3.2, 3.8, 4.3, 5.0, 5.5],
1063
+ "date": pd.date_range("2022-01-03", "2022-01-09"),
1064
+ "string": ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
1065
+ },
1066
+ )
1067
+ bar = df.hvplot.bar(x="string", y="actual", color="#f16a6f", legend="bottom", xlabel="day", ylabel="value")
1068
+ bar
1069
+
1070
+ You can overlay for example a line plot via
1071
+
1072
+ .. code-block::
1073
+
1074
+ forecast_line = df.hvplot.line(x="string", y="forecast", color="#1e85f7", line_width=5, legend="bottom")
1075
+ forecast_markers = df.hvplot.scatter(x="string", y="forecast", color="#1e85f7", size=100, legend="bottom")
1076
+ bar * forecast_line * forecast_markers
1077
+
1078
+ .. code-block::
1079
+
1080
+ df.hvplot.bar(stacked=True, rot=90, color=["#457278", "#615078"])
1081
+
1082
+ References
1083
+ ----------
1084
+
1085
+ - Bokeh: https://docs.bokeh.org/en/latest/docs/reference/models/glyphs/vbar.html
1086
+ - HoloViews: https://holoviews.org/reference/elements/bokeh/Bars.html
1087
+ - Matplotlib: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.bar.html
1088
+ - Pandas: https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.plot.bar.html
1089
+ - Plotly: https://plotly.com/python/bar-charts/
1090
+ - Wiki: https://en.wikipedia.org/wiki/Bar_chart
1091
+ """
1092
+ return self(x, y, kind='bar', **kwds)
1093
+
1094
+ def barh(self, x=None, y=None, **kwds):
1095
+ """
1096
+ A horizontal bar plot
1097
+
1098
+ A `barh` plot represents categorical data with rectangular bars
1099
+ with heights proportional to the values that they represent. The y-axis of the chart
1100
+ plots categories and the x-axis represents the value scale.
1101
+ The bars are of equal width which allows for instant comparison of data.
1102
+
1103
+ `barh` can be used on dataframes with regular Index or MultiIndex.
1104
+
1105
+ Reference: https://hvplot.holoviz.org/reference/tabular/barh.html
1106
+
1107
+ Parameters
1108
+ ----------
1109
+ **kwds : optional
1110
+ Additional keywords arguments are documented in `hvplot.help('image')`.
1111
+
1112
+ Returns
1113
+ -------
1114
+ A Holoviews object. You can `print` the object to study its composition and run
1115
+
1116
+ .. code-block::
1117
+
1118
+ import holoviews as hv
1119
+ hv.help(the_holoviews_object)
1120
+
1121
+ to learn more about its parameters and options.
1122
+
1123
+ Examples
1124
+ --------
1125
+
1126
+ .. code-block::
1127
+
1128
+ import hvplot.pandas
1129
+ import pandas as pd
1130
+
1131
+ df = pd.DataFrame(
1132
+ {
1133
+ "speed": [0.1, 17.5, 40, 48, 52, 69, 88],
1134
+ "lifespan": [2, 8, 70, 1.5, 25, 12, 28],
1135
+ },
1136
+ index=["snail", "pig", "elephant", "rabbit", "giraffe", "coyote", "horse"],
1137
+ )
1138
+ df.hvplot.barh(color=["#457278", "#615078"])
1139
+
1140
+ You can stack the bars by setting `stacked=True`
1141
+
1142
+ .. code-block::
1143
+
1144
+ df.hvplot.barh(stacked=True, color=["#457278", "#615078"])
1145
+
1146
+ References
1147
+ ----------
1148
+
1149
+ - Bokeh: https://docs.bokeh.org/en/latest/docs/reference/models/glyphs/hbar.html
1150
+ - HoloViews: https://holoviews.org/reference/elements/bokeh/Bars.html
1151
+ - Matplotlib: https://matplotlib.org/stable/gallery/lines_bars_and_markers/barh.html
1152
+ - Pandas: https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.plot.barh.html
1153
+ - Plotly: https://plotly.com/python/horizontal-bar-charts/
1154
+ - Wiki: https://en.wikipedia.org/wiki/Bar_chart
1155
+ """
1156
+ return self(x, y, kind='barh', **kwds)
1157
+
1158
+ def box(self, y=None, by=None, **kwds):
1159
+ """
1160
+ The `box` plot gives you a visual idea about the *locality*, *spread* and *skewness* of
1161
+ numerical data through their quartiles. It is also known as *box and whiskers plot*.
1162
+
1163
+ `box` plots are most useful when grouped by additional dimensions.
1164
+
1165
+ Reference: https://hvplot.holoviz.org/reference/tabular/box.html
1166
+
1167
+ Parameters
1168
+ ----------
1169
+ y : string or sequence
1170
+ Field(s) in the *wide* data to compute distribution from. If none is provided all
1171
+ numerical fields will be used.
1172
+ by : string or sequence
1173
+ Field in the *long* data to group by.
1174
+ kwds : optional
1175
+ Additional keywords arguments are documented in `hvplot.help('box')`.
1176
+
1177
+ Returns
1178
+ -------
1179
+ A Holoviews object. You can `print` the object to study its composition and run
1180
+
1181
+ .. code-block::
1182
+
1183
+ import holoviews as hv
1184
+ hv.help(the_holoviews_object)
1185
+
1186
+ to learn more about its parameters and options.
1187
+
1188
+ Example
1189
+ -------
1190
+
1191
+ Here is an example using *wide* data.
1192
+
1193
+ .. code-block::
1194
+
1195
+ import hvplot.pandas
1196
+ import numpy as np
1197
+ import pandas as pd
1198
+
1199
+ data = np.random.randn(25, 4)
1200
+ df = pd.DataFrame(data, columns=list('ABCD'))
1201
+ df.hvplot.box()
1202
+
1203
+ Here is an example using *long* data and the `by` argument.
1204
+
1205
+ .. code-block::
1206
+
1207
+ import hvplot.pandas # noqa
1208
+ import pandas as pd
1209
+ age_list = [8, 10, 12, 14, 72, 74, 76, 78, 20, 25, 30, 35, 60, 85]
1210
+ df = pd.DataFrame({"gender": list("MMMMMMMMFFFFFF"), "age": age_list})
1211
+ df.hvplot.box(y='age', by='gender', height=400, width=400, legend=False, ylim=(0, None))
1212
+
1213
+ References
1214
+ ----------
1215
+ - Bokeh: https://docs.bokeh.org/en/latest/docs/gallery/boxplot.html
1216
+ - HoloViews: https://holoviews.org/reference/elements/bokeh/BoxWhisker.html
1217
+ - Matplotlib: https://matplotlib.org/stable/plot_types/stats/boxplot_plot.html#sphx-glr-plot-types-stats-boxplot-plot-py
1218
+ - Pandas: https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.boxplot.html
1219
+ - Plotly: https://plotly.com/python/box-plots/
1220
+ - Wiki: https://en.wikipedia.org/wiki/Box_plot
1221
+ """
1222
+ return self(kind='box', x=None, y=y, by=by, **dict(kwds, hover=False))
1223
+
1224
+ def violin(self, y=None, by=None, **kwds):
1225
+ """
1226
+ `violin` plots are similar to `box` plots, but they provide a better sense of the
1227
+ distribution of data.
1228
+
1229
+ Note that `violin` plots depend on the `scipy` library.
1230
+
1231
+ Reference: https://hvplot.holoviz.org/reference/tabular/violin.html
1232
+
1233
+ Parameters
1234
+ ----------
1235
+ y : string or sequence
1236
+ Field(s) in the *wide* data to compute distribution from. If none is provided all
1237
+ numerical fields will be used.
1238
+ by : string or sequence
1239
+ Field in the *long* data to group by.
1240
+ kwds : optional
1241
+ Additional keywords arguments are documented in `hvplot.help('violin')`.
1242
+
1243
+ Returns
1244
+ -------
1245
+ A Holoviews object. You can `print` the object to study its composition and run
1246
+
1247
+ .. code-block::
1248
+
1249
+ import holoviews as hv
1250
+ hv.help(the_holoviews_object)
1251
+
1252
+ to learn more about its parameters and options.
1253
+
1254
+ Examples
1255
+ --------
1256
+
1257
+ Here is an example using *wide* data.
1258
+
1259
+ .. code-block::
1260
+
1261
+ import hvplot.pandas
1262
+ import numpy as np
1263
+ import pandas as pd
1264
+
1265
+ data = np.random.randn(25, 4)
1266
+ df = pd.DataFrame(data, columns=list('ABCD'))
1267
+ df.hvplot.violin(ylim=(-5, 5))
1268
+
1269
+ Here is an example using *long* data and the `by` argument.
1270
+
1271
+ .. code-block::
1272
+
1273
+ import hvplot.pandas # noqa
1274
+ import pandas as pd
1275
+ age_list = [8, 10, 12, 14, 72, 74, 76, 78, 20, 25, 30, 35, 60, 85]
1276
+ df = pd.DataFrame({"gender": list("MMMMMMMMFFFFFF"), "age": age_list})
1277
+ df.hvplot.violin(y='age', by='gender', height=400, width=400, legend=False, ylim=(-100, 200))
1278
+
1279
+ References
1280
+ ----------
1281
+
1282
+ - Seaborn: https://seaborn.pydata.org/generated/seaborn.violinplot.html
1283
+ - HoloViews: https://holoviews.org/reference/elements/bokeh/Violin.html
1284
+ - Matplotlib: https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.violinplot.html
1285
+ - Plotly: https://plotly.com/python/violin/
1286
+ - Wiki: https://en.wikipedia.org/wiki/Violin_plot
1287
+ """
1288
+ return self(kind='violin', x=None, y=y, by=by, **dict(kwds, hover=False))
1289
+
1290
+ def hist(self, y=None, by=None, **kwds):
1291
+ """
1292
+ A `histogram` displays an approximate representation of the distribution of continuous data.
1293
+
1294
+ Reference: https://hvplot.holoviz.org/reference/tabular/hist.html
1295
+
1296
+ Parameters
1297
+ ----------
1298
+ y : string or sequence
1299
+ Field(s) in the *wide* data to compute the distribution(s) from.
1300
+ Please note the fields should contain continuous data. Not categorical.
1301
+ by : string or sequence
1302
+ Field(s) in the *long* data to group by.
1303
+ bins : int, optional
1304
+ The number of bins
1305
+ bin_range: tuple, optional
1306
+ The lower and upper range of the bins. Default is None.
1307
+ normed : bool, optional
1308
+ If True the distribution will sum to 1. Default is False.
1309
+ cumulative: bool, optional
1310
+ If True, then a histogram is computed where each bin gives the counts in that bin plus
1311
+ all bins for smaller values. The last bin gives the total number of datapoints.
1312
+ Default is False.
1313
+ alpha : float, optional
1314
+ An alpha value between 0.0 and 1.0 to better visualize multiple fields. Default is 1.0.
1315
+ kwds : optional
1316
+ Additional keywords arguments are documented in `hvplot.help('hist')`.
1317
+
1318
+ Returns
1319
+ -------
1320
+ A Holoviews object. You can `print` the object to study its composition and run
1321
+
1322
+ .. code-block::
1323
+
1324
+ import holoviews as hv
1325
+ hv.help(the_holoviews_object)
1326
+
1327
+ to learn more about its parameters and options.
1328
+
1329
+ Examples
1330
+ --------
1331
+
1332
+ Lets display some *wide* data created by rolling two dices
1333
+
1334
+ .. code-block::
1335
+
1336
+ import hvplot.pandas
1337
+ import numpy as np
1338
+ import pandas as pd
1339
+
1340
+ df = pd.DataFrame(np.random.randint(1, 7, 6000), columns = ['one'])
1341
+ df['two'] = df['one'] + np.random.randint(1, 7, 6000)
1342
+ df.hvplot.hist(bins=12, alpha=0.5, color=["lightgreen", "pink"])
1343
+
1344
+ If you want to show the distribution of the values of a categorical column,
1345
+ you can use Pandas' method `value_counts` and `bar` as shown below
1346
+
1347
+ .. code-block::
1348
+
1349
+ import hvplot.pandas
1350
+ import pandas as pd
1351
+
1352
+ data = pd.DataFrame({
1353
+ "library": ["bokeh", "plotly", "matplotlib", "bokeh", "matplotlib", "matplotlib"]
1354
+ })
1355
+
1356
+ data["library"].value_counts().hvplot.bar()
1357
+
1358
+ References
1359
+ ----------
1360
+
1361
+ - Bokeh: https://docs.bokeh.org/en/latest/docs/gallery/histogram.html
1362
+ - HoloViews: https://holoviews.org/reference/elements/bokeh/Histogram.html
1363
+ - Pandas: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.plot.hist.html
1364
+ - Plotly: https://plotly.com/python/histograms/
1365
+ - Matplotlib: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.hist.html
1366
+ - Seaborn: https://seaborn.pydata.org/generated/seaborn.histplot.html
1367
+ - Wiki: https://en.wikipedia.org/wiki/Histogram
1368
+ """
1369
+ return self(kind='hist', x=None, y=y, by=by, **kwds)
1370
+
1371
+ def kde(self, y=None, by=None, **kwds):
1372
+ """
1373
+ The Kernel density estimate (`kde`) plot shows the distribution and spread of the data.
1374
+
1375
+ The `kde` and `density` plots are the same.
1376
+
1377
+ Reference: https://hvplot.holoviz.org/reference/tabular/kde.html
1378
+
1379
+ Parameters
1380
+ ----------
1381
+ y : string or sequence
1382
+ Field(s) in the data to compute distribution on. If not specified all numerical fields
1383
+ are used.
1384
+ by : string or sequence
1385
+ Field(s) in the data to group by.
1386
+ bandwidth : float, optional
1387
+ The bandwidth of the kernel for the density estimate. Default is None.
1388
+ cut :
1389
+ Draw the estimate to cut * bw from the extreme data points.
1390
+ n_samples : int, optional
1391
+ Number of samples to compute the KDE over. Default is 100.
1392
+ filled :
1393
+ Whether the bivariate contours should be filled. Default is True.
1394
+ kwds : optional
1395
+ Additional keywords arguments are documented in `hvplot.help('kde')`.
1396
+
1397
+ Returns
1398
+ -------
1399
+ A Holoviews object. You can `print` the object to study its composition and run
1400
+
1401
+ .. code-block::
1402
+
1403
+ import holoviews as hv
1404
+ hv.help(the_holoviews_object)
1405
+
1406
+ to learn more about its parameters and options.
1407
+
1408
+ Examples
1409
+ --------
1410
+
1411
+ Lets display a 'kde' plot from *wide* data
1412
+
1413
+ .. code-block::
1414
+
1415
+ import hvplot.pandas
1416
+ import numpy as np
1417
+ import pandas as pd
1418
+
1419
+ df = pd.DataFrame({
1420
+ 'x': [1, 2, 2.5, 3, 3.5, 4, 5],
1421
+ 'y': [4, 4, 4.5, 5, 5.5, 6, 6],
1422
+ })
1423
+ df.hvplot.kde(color=["orange", "green"])
1424
+
1425
+ Lets display a 'kde' plot from *long* data using the 'by' attribute
1426
+
1427
+ .. code-block::
1428
+
1429
+ import hvplot.pandas # noqa
1430
+ import pandas as pd
1431
+ import numpy as np
1432
+ df = pd.DataFrame({
1433
+ 'category': list('xxxxxxxyyyyyyy'),
1434
+ 'value': [1, 2, 2.5, 3, 3.5, 4, 5, 4, 4, 4.5, 5, 5.5, 6, 6],
1435
+ })
1436
+ df.hvplot.kde(by='category', filled=False)
1437
+
1438
+ References
1439
+ ----------
1440
+
1441
+ - HoloViews: https://holoviews.org/reference/elements/bokeh/Distribution.html
1442
+ - Pandas: https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.plot.kde.html
1443
+ - Plotly: https://plotly.com/python/distplot/
1444
+ - Seaborn: https://seaborn.pydata.org/generated/seaborn.kdeplot.html
1445
+ - Wiki: https://en.wikipedia.org/wiki/Kernel_density_estimation
1446
+ """
1447
+ return self(kind='kde', x=None, y=y, by=by, **kwds)
1448
+
1449
+ def density(self, y=None, by=None, **kwds):
1450
+ """
1451
+ The Kernel density estimate (`density`) plot shows the distribution and spread of the data.
1452
+
1453
+ The `kde` and `density` plots are the same.
1454
+
1455
+ Reference: https://hvplot.holoviz.org/reference/tabular/kde.html
1456
+
1457
+ Parameters
1458
+ ----------
1459
+ y : string or sequence
1460
+ Field(s) in the data to compute distribution from. If not specified all numerical fields
1461
+ are used.
1462
+ by : string or sequence
1463
+ Field(s) in the data to group by.
1464
+ bandwidth : float, optional
1465
+ The bandwidth of the kernel for the density estimate. Default is None.
1466
+ cut :
1467
+ Draw the estimate to cut * bw from the extreme data points.
1468
+ n_samples : int, optional
1469
+ Number of samples to compute the KDE over. Default is 100.
1470
+ filled :
1471
+ Whether the bivariate contours should be filled. Default is True.
1472
+ kwds : optional
1473
+ Additional keywords arguments are documented in `hvplot.help('density')`.
1474
+
1475
+ Returns
1476
+ -------
1477
+ A Holoviews object. You can `print` the object to study its composition and run
1478
+
1479
+ .. code-block::
1480
+
1481
+ import holoviews as hv
1482
+ hv.help(the_holoviews_object)
1483
+
1484
+ to learn more about its parameters and options.
1485
+
1486
+ Examples
1487
+ --------
1488
+
1489
+ Lets display a 'density' plot from *wide* data
1490
+
1491
+ .. code-block::
1492
+
1493
+ import hvplot.pandas
1494
+ import numpy as np
1495
+ import pandas as pd
1496
+
1497
+ df = pd.DataFrame({
1498
+ 'x': [1, 2, 2.5, 3, 3.5, 4, 5],
1499
+ 'y': [4, 4, 4.5, 5, 5.5, 6, 6],
1500
+ })
1501
+ df.hvplot.density(color=["orange", "green"])
1502
+
1503
+ Lets display a 'density' plot from *long* data using the 'by' attribute
1504
+
1505
+ .. code-block::
1506
+
1507
+ import hvplot.pandas # noqa
1508
+ import pandas as pd
1509
+ import numpy as np
1510
+ df = pd.DataFrame({
1511
+ 'category': list('xxxxxxxyyyyyyy'),
1512
+ 'value': [1, 2, 2.5, 3, 3.5, 4, 5, 4, 4, 4.5, 5, 5.5, 6, 6],
1513
+ })
1514
+ df.hvplot.density(by='category', filled=False)
1515
+
1516
+ References
1517
+ ----------
1518
+
1519
+ - HoloViews: https://holoviews.org/reference/elements/bokeh/Distribution.html
1520
+ - Pandas: https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.plot.kde.html
1521
+ - Plotly: https://plotly.com/python/distplot/
1522
+ - Seaborn: https://seaborn.pydata.org/generated/seaborn.kdeplot.html
1523
+ - Wiki: https://en.wikipedia.org/wiki/Kernel_density_estimation
1524
+ """
1525
+ return self(kind='kde', x=None, y=y, by=by, **kwds)
1526
+
1527
+ def table(self, columns=None, **kwds):
1528
+ """
1529
+ Displays a 'table'.
1530
+
1531
+ Reference: https://hvplot.holoviz.org/reference/tabular/table.html
1532
+
1533
+ Parameters
1534
+ ----------
1535
+ columns : string or sequence
1536
+ The field(s) to display as columns.
1537
+ sortable : bool, optional
1538
+ If True the columns are sortable. Default is False.
1539
+ selectable : bool, optional
1540
+ If True the cells are selectable. Default is False. # Todo: Describe how to use this
1541
+ **kwds : optional
1542
+ Additional keywords arguments are documented in `hvplot.help('table')`.
1543
+
1544
+ Returns
1545
+ -------
1546
+ A Holoviews object. You can `print` the object to study its composition and run
1547
+
1548
+ .. code-block::
1549
+
1550
+ import holoviews as hv
1551
+ hv.help(the_holoviews_object)
1552
+
1553
+ to learn more about its parameters and options.
1554
+
1555
+ Example
1556
+ -------
1557
+
1558
+ .. code-block::
1559
+
1560
+ import hvplot.pandas
1561
+ from bokeh.sampledata.autompg import autompg_clean as df
1562
+
1563
+ df.hvplot.table(columns=['origin', 'name', 'yr'], sortable=True, selectable=True)
1564
+
1565
+ References
1566
+ ----------
1567
+
1568
+ - HoloViews: https://holoviews.org/reference/elements/bokeh/Table.html
1569
+ - Plotly: https://plotly.com/python/table/
1570
+ - Matplotlib: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.table.html
1571
+ """
1572
+ return self(kind='table', **dict(kwds, columns=columns))
1573
+
1574
+ def dataset(self, columns=None, **kwds):
1575
+ """
1576
+ The 'dataset' wraps a tabular or gridded dataset and can be further transformed and
1577
+ annotated via methods from HoloViews.
1578
+
1579
+ Parameters
1580
+ ----------
1581
+ **kwds : optional
1582
+ Additional keywords arguments are documented in `hvplot.help('dataset')`.
1583
+
1584
+ Returns
1585
+ -------
1586
+ A Holoviews object. You can `print` the object to study its composition and run
1587
+
1588
+ .. code-block::
1589
+
1590
+ import holoviews as hv
1591
+ hv.help(the_holoviews_object)
1592
+
1593
+ to learn more about its parameters and options.
1594
+
1595
+ Example
1596
+ -------
1597
+
1598
+ .. code-block::
1599
+
1600
+ import hvplot.pandas
1601
+ import pandas as pd
1602
+
1603
+ data = pd.DataFrame({"x": ['a', 'b', 'c'], "y": [1, 2, 3]})
1604
+ data.hvplot.dataset()
1605
+
1606
+ References
1607
+ ----------
1608
+
1609
+ - HoloViews Tabular: https://holoviews.org/getting_started/Tabular_Datasets.html
1610
+ - HoloViews Gridded: https://holoviews.org/getting_started/Gridded_Datasets.html
1611
+ """
1612
+ return self(kind='dataset', **dict(kwds, columns=columns))
1613
+
1614
+ def points(self, x=None, y=None, **kwds):
1615
+ """
1616
+ A `points` plot visualizes positions in a 2D space. This is useful for example for
1617
+ geographic plots.
1618
+
1619
+ There is no assumption that 'y' depends on 'x'. This is different from a `scatter` plot
1620
+ which assumes that `y` depends `x`.
1621
+
1622
+ Reference: https://hvplot.holoviz.org/reference/geopandas/points.html
1623
+
1624
+ Parameters
1625
+ ----------
1626
+ x : string, optional
1627
+ The coordinate variable along the x-axis. Default is the first numeric field.
1628
+ y : string, optional
1629
+ The coordinate variable along the y-axis. Default is the second numeric field.
1630
+ c : string, optional
1631
+ The dimension to color the points by
1632
+ s : int, optional, also available as 'size'
1633
+ The size of the marker
1634
+ marker : string, optional
1635
+ The marker shape specified above can be any supported by matplotlib, e.g. s, d, o etc.
1636
+ See https://matplotlib.org/stable/api/markers_api.html.
1637
+ scale: number, optional
1638
+ Scaling factor to apply to point scaling.
1639
+ logz : bool
1640
+ Whether to apply log scaling to the z-axis. Default is False.
1641
+ **kwds : optional
1642
+ Additional keywords arguments are documented in `hvplot.help('points')`.
1643
+
1644
+ Returns
1645
+ -------
1646
+ A Holoviews object. You can `print` the object to study its composition and run
1647
+
1648
+ .. code-block::
1649
+
1650
+ import holoviews as hv
1651
+ hv.help(the_holoviews_object)
1652
+
1653
+ to learn more about its parameters and options.
1654
+
1655
+ Examples
1656
+ --------
1657
+
1658
+ .. code-block::
1659
+
1660
+ import hvplot.pandas
1661
+ import pandas as pd
1662
+
1663
+ data = pd.DataFrame(dict(x=[49.9, 50.0, 50.1, 50.2], y=[50.2, 49.9, 50.0, 50.2]))
1664
+ plot = data.hvplot.points(color="green", size=100, marker="square")
1665
+ plot
1666
+
1667
+ References
1668
+ ----------
1669
+
1670
+ - HoloViews: https://holoviews.org/reference/elements/bokeh/Points.html
1671
+ """
1672
+ return self(x, y, kind='points', **kwds)
1673
+
1674
+ def vectorfield(self, x=None, y=None, angle=None, mag=None, **kwds):
1675
+ """
1676
+ `vectorfield visualizes vectors given by the (`x , `y`) starting point, a magnitude (`mag`)
1677
+ and an `angle` . A `vectorfield` plot is also known as a `quiver` plot.
1678
+
1679
+ Reference: https://hvplot.holoviz.org/reference/xarray/vectorfield.html
1680
+
1681
+ Parameters
1682
+ ----------
1683
+ x : string
1684
+ Field name to draw x-positions from
1685
+ y : string
1686
+ Field name to draw y-positions from
1687
+ mag : string
1688
+ Magnitude
1689
+ angle : string
1690
+ Angle in radians.
1691
+ **kwds : optional
1692
+ Additional keywords arguments are documented in `hvplot.help('vectorfield')`.
1693
+
1694
+ Returns
1695
+ -------
1696
+ A Holoviews object. You can `print` the object to study its composition and run
1697
+
1698
+ .. code-block::
1699
+
1700
+ import holoviews as hv
1701
+ hv.help(the_holoviews_object)
1702
+
1703
+ to learn more about its parameters and options.
1704
+
1705
+ Example
1706
+ -------
1707
+
1708
+ .. code-block::
1709
+
1710
+ import hvplot.pandas
1711
+ import numpy as np
1712
+ import pandas as pd
1713
+
1714
+ data = pd.DataFrame(
1715
+ dict(
1716
+ x=[49.9, 50.0, 50.1, 50.2],
1717
+ y=[50.2, 49.9, 50.0, 50.2],
1718
+ angle=[2 * np.pi, np.pi, np.pi, np.pi],
1719
+ mag=[0.01, 0.02, -0.02, -0.01],
1720
+ )
1721
+ )
1722
+ data.hvplot.vectorfield(x="x", y="y", angle="angle", mag="mag")
1723
+
1724
+ References
1725
+ ----------
1726
+
1727
+ - Bokeh: https://docs.bokeh.org/en/latest/docs/gallery/quiver.html
1728
+ - HoloViews: https://holoviews.org/reference/elements/bokeh/VectorField.html
1729
+ - Matplotlib: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.quiver.html
1730
+ - Plotly: https://plotly.com/python/quiver-plots/
1731
+ - Wiki: https://simple.wikipedia.org/wiki/Vector_field
1732
+ """
1733
+ return self(x, y, angle=angle, mag=mag, kind='vectorfield', **kwds)
1734
+
1735
+ def polygons(self, x=None, y=None, c=None, **kwds):
1736
+ """
1737
+ Polygon plot for geopandas dataframes.
1738
+
1739
+ Reference: https://hvplot.holoviz.org/reference/geopandas/polygons.html
1740
+
1741
+ Parameters
1742
+ ----------
1743
+ c : string, optional
1744
+ The dimension to color the polygons by
1745
+ logz : bool
1746
+ Enables logarithmic colormapping. Default is False.
1747
+ geo : bool, optional
1748
+ Whether the plot should be treated as geographic (and assume
1749
+ PlateCarree, i.e. lat/lon coordinates).
1750
+ **kwds : optional
1751
+ Additional keywords arguments are documented in `hvplot.help('polygons')`.
1752
+
1753
+ Returns
1754
+ -------
1755
+ A Holoviews object. You can `print` the object to study its composition and run
1756
+
1757
+ .. code-block::
1758
+
1759
+ import holoviews as hv
1760
+ hv.help(the_holoviews_object)
1761
+
1762
+ to learn more about its parameters and options.
1763
+
1764
+ Examples
1765
+ --------
1766
+
1767
+ .. code-block::
1768
+
1769
+ import geopandas as gpd
1770
+ import hvplot.pandas
1771
+
1772
+ countries = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
1773
+ countries.hvplot.polygons(geo=True, c='pop_est', hover_cols='all')
1774
+ """
1775
+ return self(x, y, c=c, kind='polygons', **kwds)
1776
+
1777
+ def paths(self, x=None, y=None, c=None, **kwds):
1778
+ """
1779
+ LineString and LineRing plot for geopandas dataframes.
1780
+
1781
+ Parameters
1782
+ ----------
1783
+ **kwds : optional
1784
+ Additional keywords arguments are documented in `hvplot.help('paths')`.
1785
+
1786
+ Returns
1787
+ -------
1788
+ A Holoviews object. You can `print` the object to study its composition and run
1789
+
1790
+ .. code-block::
1791
+
1792
+ import holoviews as hv
1793
+ hv.help(the_holoviews_object)
1794
+
1795
+ to learn more about its parameters and options.
1796
+
1797
+ References
1798
+ ----------
1799
+
1800
+ - HoloViews: https://holoviews.org/reference/elements/bokeh/Path.html
1801
+ """
1802
+ return self(x, y, c=c, kind='paths', **kwds)
1803
+
1804
+ def labels(self, x=None, y=None, text=None, **kwds):
1805
+ """
1806
+ Labels plot.
1807
+
1808
+ `labels` are mostly useful when overlaid on top of other plots using the `*`
1809
+ operator.
1810
+
1811
+ Reference: https://hvplot.holoviz.org/reference/tabular/labels.html
1812
+
1813
+ Parameters
1814
+ ----------
1815
+ x : string, optional
1816
+ The coordinate variable along the x-axis
1817
+ y : string, optional
1818
+ The coordinate variable along the y-axis
1819
+ text : string, optional
1820
+ The column to draw the text labels from; it's also possible to
1821
+ provide a template string containing the column names to
1822
+ automatically format the text, e.g. "{col1}, {col2}".
1823
+ **kwds : optional
1824
+ Additional keywords arguments are documented in `hvplot.help('labels')`.
1825
+
1826
+ Returns
1827
+ -------
1828
+ A Holoviews object. You can `print` the object to study its composition and run
1829
+
1830
+ .. code-block::
1831
+
1832
+ import holoviews as hv
1833
+ hv.help(the_holoviews_object)
1834
+
1835
+ to learn more about its parameters and options.
1836
+
1837
+ Examples
1838
+ --------
1839
+
1840
+ .. code-block::
1841
+
1842
+ import hvplot.pandas
1843
+ import pandas as pd
1844
+
1845
+ df = pd.DataFrame(
1846
+ {'City': ['Buenos Aires', 'Brasilia', 'Santiago', 'Bogota', 'Caracas'],
1847
+ 'Country': ['Argentina', 'Brazil', 'Chile', 'Colombia', 'Venezuela'],
1848
+ 'Latitude': [-34.58, -15.78, -33.45, 4.60, 10.48],
1849
+ 'Longitude': [-58.66, -47.91, -70.66, -74.08, -66.86],
1850
+ 'Color': ['blue', 'green', 'white', 'black', 'yellow']})
1851
+
1852
+ df.hvplot.points(x='Longitude', y='Latitude') * \
1853
+ df.hvplot.labels(x='Longitude', y='Latitude', text='City', text_baseline="bottom")
1854
+
1855
+ References
1856
+ ----------
1857
+
1858
+ - Bokeh: https://docs.bokeh.org/en/latest/docs/reference/models/glyphs/text.html
1859
+ - HoloViews: https://holoviews.org/reference/elements/bokeh/Labels.html
1860
+ - Matplotlib: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.text.html#matplotlib.pyplot.text
1861
+ - Plotly: https://plotly.com/python/text-and-annotations/
1862
+ """
1863
+ return self(x, y, text=text, kind='labels', **kwds)
1864
+
1865
+
1866
+ class hvPlotTabularPolars(hvPlotTabular):
1867
+ def _get_converter(self, x=None, y=None, kind=None, **kwds):
1868
+ import polars as pl
1869
+
1870
+ params = dict(self._metadata, **kwds)
1871
+ x = x or params.pop('x', None)
1872
+ y = y or params.pop('y', None)
1873
+ kind = kind or params.pop('kind', None)
1874
+
1875
+ # Find columns which should be converted for LazyDataFrame and DataFrame
1876
+ if isinstance(self._data, (pl.LazyFrame, pl.DataFrame)):
1877
+ if params.get('hover_cols') == 'all':
1878
+ columns = list(self._data.columns)
1879
+ else:
1880
+ possible_columns = [
1881
+ [v] if isinstance(v, str) else v
1882
+ for v in params.values()
1883
+ if isinstance(v, (str, list))
1884
+ ]
1885
+
1886
+ columns = (set(self._data.columns) & set(itertools.chain(*possible_columns))) or {
1887
+ self._data.columns[0]
1888
+ }
1889
+ if y is None:
1890
+ # When y is not specified HoloViewsConverter finds all the numeric
1891
+ # columns and use them as y values (see _process_chart_y). We meed
1892
+ # to include these columns too.
1893
+ columns |= set(self._data.select(pl.col(pl.NUMERIC_DTYPES)).columns)
1894
+ xs = x if is_list_like(x) else (x,)
1895
+ ys = y if is_list_like(y) else (y,)
1896
+ columns |= {*xs, *ys}
1897
+ columns.discard(None)
1898
+ # Reorder the columns as in the data.
1899
+ columns = sorted(columns, key=lambda c: self._data.columns.index(c))
1900
+
1901
+ if isinstance(self._data, pl.DataFrame):
1902
+ data = self._data.select(columns).to_pandas()
1903
+ elif isinstance(self._data, pl.Series):
1904
+ data = self._data.to_pandas()
1905
+ elif isinstance(self._data, pl.LazyFrame):
1906
+ data = self._data.select(columns).collect().to_pandas()
1907
+ else:
1908
+ raise ValueError('Only Polars DataFrame, Series, and LazyFrame are supported')
1909
+
1910
+ return HoloViewsConverter(data, x, y, kind=kind, **params)
1911
+
1912
+
1913
+ class hvPlot(hvPlotTabular):
1914
+ """
1915
+ The plotting method: `df.hvplot(...)` creates a plot similarly to the familiar Pandas
1916
+ `df.plot` method.
1917
+
1918
+ For more detailed options use a specific plotting method, e.g. `df.hvplot.line`.
1919
+
1920
+ Reference: https://hvplot.holoviz.org/reference/index.html
1921
+
1922
+ Parameters
1923
+ ----------
1924
+ x : string, optional
1925
+ Field name(s) to draw x-positions from. If not specified, the index is
1926
+ used.
1927
+ y : string or list, optional
1928
+ Field name(s) to draw y-positions from. If not specified, all numerical
1929
+ fields are used.
1930
+ kind : string, optional
1931
+ The kind of plot to generate, e.g. 'area', 'bar', 'line', 'scatter' etc. To see the
1932
+ available plots run `print(df.hvplot.__all__)`.
1933
+ **kwds : optional
1934
+ Additional keywords arguments are documented in `hvplot.help('scatter')` or similar
1935
+ depending on the kind of plot.
1936
+
1937
+ Returns
1938
+ -------
1939
+ A Holoviews object. You can `print` the object to study its composition and run `hv.help` on
1940
+ the object to learn more about its parameters and options.
1941
+
1942
+ Examples
1943
+ --------
1944
+
1945
+ .. code-block::
1946
+
1947
+ import hvplot.pandas
1948
+ import pandas as pd
1949
+
1950
+ df = pd.DataFrame(
1951
+ {
1952
+ "actual": [100, 150, 125, 140, 145, 135, 123],
1953
+ "forecast": [90, 160, 125, 150, 141, 141, 120],
1954
+ "numerical": [1.1, 1.9, 3.2, 3.8, 4.3, 5.0, 5.5],
1955
+ "date": pd.date_range("2022-01-03", "2022-01-09"),
1956
+ "string": ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
1957
+ },
1958
+ )
1959
+ line = df.hvplot.line(
1960
+ x="numerical",
1961
+ y=["actual", "forecast"],
1962
+ ylabel="value",
1963
+ legend="bottom",
1964
+ height=500,
1965
+ color=["steelblue", "teal"],
1966
+ alpha=0.7,
1967
+ line_width=5,
1968
+ )
1969
+ line
1970
+
1971
+ You can can add *markers* to a `line` plot by overlaying with a `scatter` plot.
1972
+
1973
+ .. code-block::
1974
+
1975
+ markers = df.hvplot.scatter(
1976
+ x="numerical", y=["actual", "forecast"], color=["#f16a6f", "#1e85f7"], size=50
1977
+ )
1978
+ line * markers
1979
+
1980
+ Please note that you can pass widgets or reactive functions as arguments instead of
1981
+ literal values, c.f. https://hvplot.holoviz.org/user_guide/Widgets.html.
1982
+ """
1983
+
1984
+ __all__ = [
1985
+ 'line',
1986
+ 'step',
1987
+ 'scatter',
1988
+ 'area',
1989
+ 'errorbars',
1990
+ 'heatmap',
1991
+ 'hexbin',
1992
+ 'bivariate',
1993
+ 'bar',
1994
+ 'barh',
1995
+ 'box',
1996
+ 'violin',
1997
+ 'hist',
1998
+ 'kde',
1999
+ 'density',
2000
+ 'table',
2001
+ 'dataset',
2002
+ 'points',
2003
+ 'vectorfield',
2004
+ 'polygons',
2005
+ 'paths',
2006
+ 'labels',
2007
+ 'image',
2008
+ 'rgb',
2009
+ 'quadmesh',
2010
+ 'contour',
2011
+ 'contourf',
2012
+ 'explorer',
2013
+ ]
2014
+
2015
+ def image(self, x=None, y=None, z=None, colorbar=True, **kwds):
2016
+ """
2017
+ Image plot
2018
+
2019
+ You can use `image` to display for example geographic data with independent `latitude` and
2020
+ `longitude` fields and a third dependent field.
2021
+
2022
+ Reference: https://hvplot.holoviz.org/reference/xarray/image.html
2023
+
2024
+ Parameters
2025
+ ----------
2026
+ x : string, optional
2027
+ The coordinate variable along the x-axis
2028
+ y : string, optional
2029
+ The coordinate variable along the y-axis
2030
+ z : string, optional
2031
+ The data variable to plot
2032
+ colorbar: boolean
2033
+ Whether to display a colorbar
2034
+ kwds : optional
2035
+ To see all the keyword arguments available, run `hvplot.help('image')`.
2036
+
2037
+ Returns
2038
+ -------
2039
+ A Holoviews object. You can `print` the object to study its composition and run
2040
+
2041
+ .. code-block::
2042
+
2043
+ import holoviews as hv
2044
+ hv.help(the_holoviews_object)
2045
+
2046
+ to learn more about its parameters and options.
2047
+
2048
+ Example
2049
+ -------
2050
+
2051
+ .. code-block::
2052
+
2053
+ import hvplot.xarray
2054
+ import xarray as xr
2055
+
2056
+ ds = xr.tutorial.open_dataset('air_temperature')
2057
+ ds.hvplot.image(x='lon', y='lat', z='air', groupby='time', cmap='kbc_r')
2058
+
2059
+ References
2060
+ ----------
2061
+
2062
+ - Bokeh: https://docs.bokeh.org/en/latest/docs/gallery/image.html
2063
+ - HoloViews: https://holoviews.org/reference/elements/bokeh/Image.html
2064
+ - Matplotlib: https://matplotlib.org/stable/tutorials/introductory/images.html
2065
+ - Plotly: https://plotly.com/python/imshow/
2066
+ """
2067
+ return self(x, y, z=z, kind='image', colorbar=colorbar, **kwds)
2068
+
2069
+ def rgb(self, x=None, y=None, z=None, bands=None, **kwds):
2070
+ """
2071
+ RGB plot
2072
+
2073
+ `rgb` can be used to display images that are distributed as three separate "channels" or
2074
+ "bands".
2075
+
2076
+ Reference: https://hvplot.holoviz.org/reference/xarray/rgb.html
2077
+
2078
+ Parameters
2079
+ ----------
2080
+ x : string, optional
2081
+ The coordinate variable along the x-axis
2082
+ y : string, optional
2083
+ The coordinate variable along the y-axis
2084
+ bands : string, optional
2085
+ The coordinate variable to draw the RGB channels from
2086
+ z : string, optional
2087
+ The data variable to plot
2088
+ **kwds : optional
2089
+ Additional keywords arguments are documented in `hvplot.help('rgb')`.
2090
+
2091
+ Returns
2092
+ -------
2093
+ A Holoviews object. You can `print` the object to study its composition and run
2094
+
2095
+ .. code-block::
2096
+
2097
+ import holoviews as hv
2098
+ hv.help(the_holoviews_object)
2099
+
2100
+ to learn more about its parameters and options.
2101
+
2102
+ References
2103
+ ----------
2104
+
2105
+ - Bokeh: https://docs.bokeh.org/en/latest/docs/reference/models/glyphs/image_rgba.html
2106
+ - HoloViews: https://holoviews.org/reference/elements/bokeh/RGB.html
2107
+ - Matplotlib: https://matplotlib.org/stable/tutorials/introductory/images.html
2108
+ - Plotly: https://plotly.com/python/imshow/
2109
+ """
2110
+ if bands is not None:
2111
+ kwds['bands'] = bands
2112
+ return self(x, y, z=z, kind='rgb', **kwds)
2113
+
2114
+ def quadmesh(self, x=None, y=None, z=None, colorbar=True, **kwds):
2115
+ """
2116
+ QuadMesh plot
2117
+
2118
+ `quadmesh` allows you to plot values on an irregular grid by representing each value as a
2119
+ polygon.
2120
+
2121
+ Reference: https://hvplot.holoviz.org/reference/xarray/quadmesh.html
2122
+
2123
+ Parameters
2124
+ ----------
2125
+ x : string, optional
2126
+ The coordinate variable along the x-axis
2127
+ y : string, optional
2128
+ The coordinate variable along the y-axis
2129
+ z : string, optional
2130
+ The data variable to plot
2131
+ colorbar: boolean
2132
+ Whether to display a colorbar
2133
+ **kwds : optional
2134
+ Additional keywords arguments are documented in `hvplot.help('quadmesh')`.
2135
+
2136
+ Returns
2137
+ -------
2138
+ A Holoviews object. You can `print` the object to study its composition and run
2139
+
2140
+ .. code-block::
2141
+
2142
+ import holoviews as hv
2143
+ hv.help(the_holoviews_object)
2144
+
2145
+ to learn more about its parameters and options.
2146
+
2147
+ Examples
2148
+ --------
2149
+
2150
+ .. code-block::
2151
+
2152
+ import hvplot.xarray
2153
+ import xarray as xr
2154
+
2155
+ ds = xr.tutorial.open_dataset('rasm')
2156
+ ds.Tair.hvplot.quadmesh(x='xc', y='yc', geo=True, widget_location='bottom')
2157
+
2158
+ References
2159
+ ----------
2160
+
2161
+ - HoloViews: https://holoviews.org/reference/elements/bokeh/QuadMesh.html
2162
+ """
2163
+ return self(x, y, z=z, kind='quadmesh', colorbar=colorbar, **kwds)
2164
+
2165
+ def contour(self, x=None, y=None, z=None, colorbar=True, **kwds):
2166
+ """
2167
+ Line contour plot
2168
+
2169
+ Reference: https://hvplot.holoviz.org/reference/xarray/contour.html
2170
+
2171
+ Parameters
2172
+ ----------
2173
+ x : string, optional
2174
+ The coordinate variable along the x-axis
2175
+ y : string, optional
2176
+ The coordinate variable along the y-axis
2177
+ z : string, optional
2178
+ The data variable to plot
2179
+ levels: int, optional
2180
+ The number of contour levels
2181
+ colorbar: boolean
2182
+ Whether to display a colorbar
2183
+ **kwds : optional
2184
+ Additional keywords arguments are documented in `hvplot.help('contour')`.
2185
+
2186
+ Returns
2187
+ -------
2188
+ A Holoviews object. You can `print` the object to study its composition and run
2189
+
2190
+ .. code-block::
2191
+
2192
+ import holoviews as hv
2193
+ hv.help(the_holoviews_object)
2194
+
2195
+ to learn more about its parameters and options.
2196
+
2197
+ Examples
2198
+ --------
2199
+
2200
+ .. code-block::
2201
+
2202
+ import hvplot.xarray
2203
+ import xarray as xr
2204
+
2205
+ ds = xr.tutorial.open_dataset("air_temperature")
2206
+ ds.hvplot.contour(
2207
+ geo=True,
2208
+ tiles="EsriImagery",
2209
+ z="air",
2210
+ x="lon",
2211
+ y="lat",
2212
+ levels=20,
2213
+ clabel="T [K]",
2214
+ line_width=2,
2215
+ label="Mean Air temperature [K]",
2216
+ cmap="reds",
2217
+ )
2218
+
2219
+ References
2220
+ ----------
2221
+
2222
+ - HoloViews: https://holoviews.org/reference/elements/bokeh/Contours.html
2223
+ - Matplotlib: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.contour.html
2224
+ - Plotly: https://plotly.com/python/contour-plots/
2225
+ """
2226
+ return self(x, y, z=z, kind='contour', colorbar=colorbar, **kwds)
2227
+
2228
+ def contourf(self, x=None, y=None, z=None, colorbar=True, **kwds):
2229
+ """
2230
+ Filled contour plot
2231
+
2232
+ Reference. https://hvplot.holoviz.org/reference/xarray/contourf.html
2233
+
2234
+ Parameters
2235
+ ----------
2236
+ x : string, optional
2237
+ The coordinate variable along the x-axis
2238
+ y : string, optional
2239
+ The coordinate variable along the y-axis
2240
+ z : string, optional
2241
+ The data variable to plot
2242
+ levels: int, optional
2243
+ The number of contour levels
2244
+ colorbar: boolean
2245
+ Whether to display a colorbar
2246
+ **kwds : optional
2247
+ Additional keywords arguments are documented in `hvplot.help('contourf')`.
2248
+
2249
+ Returns
2250
+ -------
2251
+ A Holoviews object. You can `print` the object to study its composition and run
2252
+
2253
+ .. code-block::
2254
+
2255
+ import holoviews as hv
2256
+ hv.help(the_holoviews_object)
2257
+
2258
+ to learn more about its parameters and options.
2259
+
2260
+ Examples
2261
+
2262
+ .. code-block::
2263
+
2264
+ import hvplot.xarray
2265
+ import xarray as xr
2266
+
2267
+ ds = xr.tutorial.open_dataset("air_temperature")
2268
+ ds.hvplot.contourf(
2269
+ geo=True,
2270
+ coastline=True,
2271
+ z="air",
2272
+ x="lon",
2273
+ y="lat",
2274
+ levels=20,
2275
+ clabel="T [K]",
2276
+ line_width=2,
2277
+ label="Mean Air temperature [K]",
2278
+ cmap="reds",
2279
+ )
2280
+
2281
+ References
2282
+ ----------
2283
+
2284
+ - HoloViews: https://holoviews.org/reference/elements/bokeh/Contours.html
2285
+ - Matplotlib: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.contour.html
2286
+ - Plotly: https://plotly.com/python/contour-plots/
2287
+ """
2288
+ return self(x, y, z=z, kind='contourf', colorbar=colorbar, **kwds)