Friday, March 22, 2019

JupyterとPygalで半円グラフを表示する

半円グラフを表示するには、以下のサンプルのようにhalf_pieを使用します。

〇サンプルコード
%matplotlib inline
import pandas as pd
import pygal as pg
from pygal.style import Style
style1 = Style(
  colors=('#3060ff', '#ff0000', '#00ff00')
)
chart = pg.Pie(half_pie=True, height=300, style=style1)
df = pd.DataFrame({'商品A':[55], '商品B':[30], '商品C':[15]})
chart.x_labels = ['percent']
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: