hvPlot-Beispiele#

Installation#

Um die Beispiele ausführen zu können, muss zusätzlich Snappy installiert werden.

Mit Spack könnt ihr Snappy in eurem Kernel bereitstellen, z.B. mit:

$ spack env activate python-38
$ snappy@1.1.8%gcc@11.2.0~ipo+pic+shared

Alternativ könnt ihr Snappy auch mit anderen Paketmanagern installieren, z.B.

  • Für Debian/Ubuntu:

    $ sudo apt install libsnappy-dev
    
  • Für Windows:

    Snappy benötigt Microsoft Visual C++ ≥ 14.0. Dies kann installiert werden mit den Microsoft C++ Build Tools.

  • Für Mac OS:

    $ brew install snappy
    

Anschließend sollten für euren Kernel noch weitere Pakete installiert werden, z.B. mit:

$ pipenv install intake intake-parquet s3fs python-snappy pyviz-comms
…

Einführung#

Als erstes importieren wir Numpy und Pandas um anschließend einen kleinen Satz zufälliger Daten zu erstellen:

[1]:
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()
[1]:
A B C D
2000-01-01 -0.267304 -0.005315 0.601458 0.174785
2000-01-02 0.138013 -1.331913 1.916291 0.993524
2000-01-03 0.303027 -0.175186 1.467751 2.096146
2000-01-04 1.032444 -0.733473 2.208890 1.925239
2000-01-05 1.151775 1.341931 2.166011 0.697053

Pandas.plot ()-API#

Pandas bietet standardmäßig Matplotlib-basiertes Plotten mit der .plot()-Methode:

[2]:
%matplotlib inline

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

Das Ergebnis ist ein PNG-Bild, das leicht angezeigt werden kann, ansonsten aber statisch ist.

Hinweis: In Pandas > 0.25.0 kann das Backend ausgetauscht werden, z.B. mit pd.options.backend.plotting == 'holoviews',. Weitere Informationen hierzu findet ihr unter Pandas-API.

.hvplot()#

Wenn wir statt %matplotlib inline zu import hvplot.pandas und der df.hvplot-Methode wechseln, , wird jetzt ein interaktiv erforschbares Bokeh-Diagramm erzeugt mit Verschieben und Vergrößern/Verkleinern sowie anklickbaren Legenden:

[3]:
import hvplot.pandas

df.hvplot()