Thursday, March 21, 2019

JupyterとPygalで折れ線グラフ表示する

折れ線グラフ表示するには、以下のサンプルのようにLineを使用します。

〇サンプルコード
%matplotlib inline
import pandas as pd
import pygal as pg
from pygal.style import Style
style1 = Style(
  colors=('#3060ff', '#ff0000', '#00ff00')
)
chart = pg.Line(height=300, style=style1)
df = pd.DataFrame({'商品A': [25, 20, 30], '商品B':[7, 30, 50], '商品C':[12, 40, 80]})
chart.x_labels = ['2017年', '2018年', '2019年']
chart.add('商品A', df['商品A'])
chart.add('商品B', df['商品B'])
chart.add('商品C', df['商品C'])
display({'image/svg+xml': chart.render(is_unicode=True)}, raw=True)

○出力画像


〇関連項目
VagrantでJupyter Lab、Pygalをインストールした仮想マシン(Ubuntu18.04)を構築する
http://serverarekore.blogspot.com/2019/03/vagrantjupyter-labpygalubuntu1804.html

VagrantでJupyter Lab、Pygalをインストールした仮想マシン(Debian Stretch/9.6)を構築する
http://serverarekore.blogspot.com/2019/03/vagrantjupyter-labpygaldebian-stretch96.html

No comments: