Comments¶
DataFrame.hvplot
(via the Python packagehvplot
) is the most convenient way to use HoloViews.If you want to use HoloViews directly, it is better to create a HoloViews.Dataset object and use it for visualization.
The
groupby
option generates a plot with a dropdown list for interactively showing plots of different groups. You can overlay plots of different groups together on the same plot simplify by calling the.overlay()
method.
In [1]:
!curl -sSL www.legendu.net/media/data/iris.csv -o iris.csv
In [2]:
import pandas as pd
In [3]:
iris = pd.read_csv("iris.csv")
iris.head()
Out[3]:
Use the hvplot
Library¶
In [4]:
import holoviews as hv
# import hvplot
import hvplot.pandas
# hv.extension("bokeh")
In [5]:
fig = iris.hvplot.scatter("sepal_width_cm", "sepal_length_cm")
fig
Out[5]:
In [6]:
type(fig)
Out[6]:
In [7]:
iris.hvplot.scatter("sepal_width_cm", "sepal_length_cm", groupby="species")
Out[7]:
In [8]:
iris.hvplot.scatter("sepal_width_cm", "sepal_length_cm", groupby="species").overlay()
Out[8]:
In [9]:
iris.hvplot.scatter("petal_width_cm", "petal_length_cm", groupby="species").overlay()
Out[9]:
Use The HoloViews Library Directly¶
Pass a tuple (of x and y) to HoloViews.Scatter
.
You have to manually specify the labels for x and y-axis,
otherwise, the default lables x
and y
will be used.
In [10]:
%%opts Scatter [width=600 height=500 tools=["hover"]]
hv.Scatter((iris.sepal_width_cm, iris.sepal_length_cm)).opts(xlabel="Sepal Width", ylabel="Sepal Length")
Out[10]:
In [11]:
%%opts Scatter [width=600 height=500 tools=['hover']]
hv.Scatter(iris, kdims="sepal_width_cm", vdims="sepal_length_cm")
Out[11]:
Use Dataset
In The HoloViews Library¶
In [12]:
%%opts Scatter [width=600 height=500 tools=["hover"]]
hv.Scatter(iris, kdims=["sepal_width_cm", "species"], vdims=["sepal_length_cm"])
Out[12]:
In [13]:
hv.Dataset(iris).to.scatter("sepal_width_cm", "sepal_length_cm", groupby=[])
Out[13]:
In [14]:
hv.Dataset(iris).to.scatter("sepal_width_cm", "sepal_length_cm", groupby="species")
Out[14]:
In [15]:
%%opts Scatter [width=600 height=500]
hv.Dataset(iris).to.scatter("sepal_width_cm", "sepal_length_cm", groupby="species").overlay()
Out[15]:
In [ ]: