Holovizエコシステムは、Pythonでのデータ可視化をより簡単かつ強力にするための一連の互換性のあるツール群です。データのインポートやクリーニング、探索、仮説検証、正確で説得力のある図の生成、ライブアプリの共有・展開など、データ分析のあらゆる段階をサポートします。
主な特徴は以下の通りです。
代表的なコンポーネントには、以下があります。
このように、HolovizはPythonの科学技術スタックの上に構築され、データの可視化を包括的に支援するエコシステムです。
hvplot は Holoviz エコシステム(Holoviews, Panel, Datashader など)の一部として開発された、 pandas / xarray / Dask データをそのまま可視化できる高水準 API です。
特に、「コード量を増やさずにインタラクティブな可視化をしたい」というニーズに強いです。
hvplot は pandas の拡張として動作します。
import hvplot.pandas
これだけで、pandas の DataFrame / Series に .hvplot メソッドが追加されます。 デフォルトではバックエンドに Bokeh が使われますが、matplotlibを指定す ることも可能です。
!pip install hvplot
import pandas as pd
import matplotlib.pyplot as plt
# Sample DataFrame
data = {'Year': [2017, 2018, 2019, 2020, 2021],
'Sales': [250, 300, 400, 350, 500]}
df = pd.DataFrame(data)
# Plotting a line graph
df.plot(x='Year', y='Sales', kind='line')
plt.xlabel('Year')
plt.ylabel('Sales')
plt.title('Yearly Sales')
plt.show()
import hvplot.pandas
#hvplot.extension('bokeh')
plot = df.hvplot(x='Year', y='Sales', kind='line')
plot.opts(xlabel='Year')
plot.opts(ylabel='Sales')
plot.opts(title='Yearly Sales')
hvplot.extension('matplotlib')
plot2 = df.hvplot(x='Year', y='Sales',kind='line')
plot2.opts(xlabel='Year')
plot2.opts(ylabel='Sales')
plot2.opts(title='Yearly Sales')
hvplot は Holoviews を内部で使っているため、 ズーム・パン・ホバー・ツールバーが自動で付きます。
追加コードなしで、次のような操作が可能になります。
hvplotでグラフを描画するときは、hbplotのkindオプションにグラフの種別 を文字列で指定するか、メソッドとして指定するかする。
※ pie chart は公式にサポートされていません。
.opts を使うことで、軸ラベル・色・フォントなどを調整できます。
import pandas as pd
import hvplot.pandas
df=pd.DataFrame({'x':[1,2,3],'y':[4,5,2]})
df.hvplot.line(x='x',y='y')
df=pd.DataFrame({'section': ['Div-A', 'Div-B', 'Div-c', 'Div-D', 'Div-E'],'students': [23,17,35,29,12]})
df.hvplot.bar(x='section',y='students')
df=pd.DataFrame({'data':[12,80,30,65,60,73,55,54]})
plot=df.hvplot.hist(y='data', bins = 'auto')
plot.opts(title="HISTOGRAM")
plot.opts(xlabel='MARKS')
plot.opts(ylabel='STUDENTS')
plot
girls_grades = [83, 90, 71, 80, 100, 87, 92, 99, 40, 34]
boys_grades = [70, 39, 59, 43, 100, 45, 74, 95, 87, 30]
grades_range = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
df=pd.DataFrame({'girls_grades':girls_grades,'boys_grades':boys_grades,'grades_range':grades_range})
plot1=df.hvplot.scatter(x='grades_range', y='girls_grades', color='r')
plot2=df.hvplot.scatter(x='grades_range', y='boys_grades', color='b')
plot=plot1*plot2
plot.opts(xlabel='Grades Range')
plot.opts(ylabel='Grades Scored')
plot.opts(title='scatter plot')
plot