Introduction#

The PyData ecosystem has a number of core Python data containers that allow users to work with a wide array of datatypes, including:

  • Pandas: DataFrame, Series (columnar/tabular data)

  • Rapids cuDF: GPU DataFrame, Series (columnar/tabular data)

  • Dask: DataFrame, Series (distributed/out of core arrays and columnar data)

  • XArray: Dataset, DataArray (labelled multidimensional arrays)

  • Streamz: DataFrame(s), Series(s) (streaming columnar data)

  • Intake: DataSource (data catalogues)

  • GeoPandas: GeoDataFrame (geometry data)

  • NetworkX: Graph (network graphs)

Many of these libraries have the concept of a high-level plotting API that lets a user generate common plot types very easily. The native plotting APIs are generally built on Matplotlib, which provides a solid foundation, but means that users miss out the benefits of modern, interactive plotting libraries for the web like Bokeh and HoloViews.

hvPlot provides a high-level plotting API built on HoloViews that provides a general and consistent API for plotting data in all the formats mentioned above.

As a first simple illustration of using hvPlot, let’s create a small set of random data in Pandas to explore:

import numpy as np
import pandas as pd

index = pd.date_range('1/1/2000', periods=1000)
df = pd.DataFrame(np.random.randn(1000, 4), index=index, columns=list('ABCD')).cumsum()

df.head()
A B C D
2000-01-01 -0.412654 0.561403 1.795590 0.678492
2000-01-02 1.122788 -0.238317 2.209365 0.862654
2000-01-03 0.594649 -0.038293 -0.185135 -0.517982
2000-01-04 -0.218272 -1.104669 -0.548176 -0.642279
2000-01-05 1.694364 -2.048766 -0.907424 -0.662521

Pandas default .plot()#

Pandas provides Matplotlib-based plotting by default, using the .plot() method:

%matplotlib inline

df.plot();
../_images/a33bec9ef0763f1dc1acc4f17309dcea913012589288b3664cbf0f90e3d15462.png

The result is a PNG image that displays easily, but is otherwise static.

Switching Pandas backend#

To allow using hvPlot directly with Pandas we have to import hvplot.pandas and swap the Pandas backend with:

import hvplot.pandas  # noqa

pd.options.plotting.backend = 'holoviews'