Thursday, May 30, 2019

Pillowで扇形を描画する

Pillowで扇形を描画するには、以下のサンプルコードのようにpiesliceメソッドを使用します。

pillow-pie.py
# coding=UTF-8
from PIL import Image
from PIL import ImageDraw

# 扇形を描画する
img1 = Image.new("RGB", (100,100), "#ffffff")
draw = ImageDraw.Draw(img1)
draw.pieslice((10,10)+(89,89), 90, 180, outline="#000000", fill="#bbddff")
del draw

img1.save("/tmp/pillow-pie.png")

出力画像(pillow-pie.png)


Tuesday, May 28, 2019

Pillowでポリゴンを描画する

Pillowでポリゴンを描画するには、以下のサンプルコードのようにpolygonメソッドを使用します。

pillow-polygon.py
# coding=UTF-8
from PIL import Image
from PIL import ImageDraw
# ポリゴンを描画する
img1 = Image.new("RGB", (100,100), (0xff, 0xff, 0xff))
draw = ImageDraw.Draw(img1)
draw.polygon((10,10)+(10,89)+(89,10), outline=(0x00, 0x00, 0x00), fill=(0xbb, 0xdd, 0xff))
del draw
img1.save("/tmp/pillow-polygon.png")

〇出力画像(pillow-polygon.png)


〇関連情報
Dockerでpython3.7とPillowをインストールしたコンテナ(Alpine3.9ベース)を作成する

Saturday, May 25, 2019

Pillowで円を描画する

Pillowで円を描画するには、以下のサンプルコードのようにellipseメソッドを使用します。

pillow-ellipse.py
# coding=UTF-8
from PIL import Image
from PIL import ImageDraw
# 円を描画する
img1 = Image.new("RGB", (100,100), (0xff, 0xff, 0xff))
draw = ImageDraw.Draw(img1)
draw.ellipse((0,0,99,99), outline=(0x00, 0x00, 0x00), fill=(0xbb, 0xdd, 0xff))
del draw
img1.save("/tmp/pillow-ellipse.png")

〇出力画像(pillow-ellipse.png)


〇関連情報
Dockerでpython3.7とPillowをインストールしたコンテナ(Alpine3.9ベース)を作成する

Pillowで四角を描画する

Pillowで四角を描画するには、以下のサンプルコードのようにrectangleメソッドを使用します。

pillow-rectangle.py
# coding=UTF-8
from PIL import Image
from PIL import ImageDraw
# 四角を描画する
img1 = Image.new("RGB", (100,100), (0xff, 0xff, 0xff))
draw = ImageDraw.Draw(img1)
draw.rectangle((10,10,89,89), outline=(0x00, 0x00, 0x00), fill=(0xbb, 0xdd, 0xff))
del draw
img1.save("/tmp/pillow-rectangle.png")

〇出力画像(pillow-rectangle.png)


〇関連情報
Dockerでpython3.7とPillowをインストールしたコンテナ(Alpine3.9ベース)を作成する

Friday, May 24, 2019

Pillowで直線を描画する

Pillowで直線を描画するには、以下のサンプルコードのようにlineメソッドを使用します。

pillow-line.py
# coding=UTF-8
from PIL import Image
from PIL import ImageDraw
# 線を引く
img1 = Image.new("RGB", (100,100), (0xff, 0xff, 0xff))
draw = ImageDraw.Draw(img1)
draw.line((0,100)+(100,0), fill=(0xbb, 0xdd, 0xff), width=2)
del draw
img1.save("/tmp/pillow-line.png")

〇出力画像(pillow-line.png)


〇関連情報
Dockerでpython3.7とPillowをインストールしたコンテナ(Alpine3.9ベース)を作成する

Saturday, March 23, 2019

JupyterとPygalで軸ラベルを回転させる

軸ラベルを回転させるには、以下のサンプルのようにx_label_rotation, y_label_rotationを使用します。

〇サンプルコード
%matplotlib inline
import pandas as pd
import pygal as pg
from pygal.style import Style
style1 = Style(
  colors=('#3060ff', '#ff0000', '#00ff00')
)
chart = pg.Bar(x_label_rotation=-45, y_label_rotation=270, height=300, style=style1)
df = pd.DataFrame({'商品A': [10], '商品B':[21], '商品C':[32]})
chart.x_labels = ['Sales']
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

JupyterとPygalで半メーターグラフを表示する

半メーターグラフを表示するには、以下のサンプルのようにSolidGaugeと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.SolidGauge(half_pie=True, inner_radius=0.7, height=300, style=style1)
df = pd.DataFrame({'商品A':[55.2], '商品B':[30.4], '商品C':[15.0]})
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

JupyterとPygalでメーターグラフを表示する

メーターグラフを表示するには、以下のサンプルのようにSolidGaugeを使用します。

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

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

JupyterとPygalで半ドーナツグラフを表示する

半ドーナツグラフを表示するには、以下のサンプルのようにhalf_pieとinner_radiusを使用します。

〇サンプルコード
%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,inner_radius=0.6, 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

JupyterとPygalでドーナツグラフを表示する

ドーナツグラフを表示するには、以下のサンプルのようにPieとinner_radiusを使用します。

〇サンプルコード
%matplotlib inline
import pandas as pd
import pygal as pg
from pygal.style import Style
style1 = Style(
  colors=('#3060ff', '#ff0000', '#00ff00')
)
chart = pg.Pie(inner_radius=0.6, 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

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

円グラフを表示するには、以下のサンプルのように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(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

JupyterとPygalで縦方向の折れ線グラフを表示する

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

〇サンプルコード
%matplotlib inline
import pandas as pd
import pygal as pg
from pygal.style import Style
style1 = Style(
  colors=('#3060ff', '#ff0000', '#00ff00')
)
chart = pg.HorizontalLine(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

JupyterとPygalで積み上げ折れ線グラフを表示する

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

〇サンプルコード
%matplotlib inline
import pandas as pd
import pygal as pg
from pygal.style import Style
style1 = Style(
  colors=('#3060ff', '#ff0000', '#00ff00')
)
chart = pg.StackedLine(height=300, style=style1, fill=True)
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

Thursday, March 21, 2019

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

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

〇サンプルコード
%matplotlib inline
import pandas as pd
import pygal as pg
from pygal.style import Style
style1 = Style(
  colors=('#3060ff', '#ff0000', '#00ff00')
  ,opacity=0.3
)
chart = pg.Line(height=300, style=style1, fill=True)
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

JupyterとPygalで折れ線グラフのY軸目盛り線を非表示にする

折れ線グラフのY軸目盛り線を非表示にするには、以下のサンプルのようにshow_y_guidesを使用します。

〇サンプルコード
%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, show_y_guides=False)
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

JupyterとPygalで折れ線グラフのX軸目盛線を表示する

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

〇サンプルコード
%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, show_x_guides=True)
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

JupyterとPygalで折れ線グラフの線を点線にする

折れ線グラフの線を点線にするには、以下のサンプルのようにstroke_styleとdasharrayを使用します。

〇サンプルコード
%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, stroke_style={'dasharray':'5,5'})
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

JupyterとPygalで折れ線グラフの点を非表示にする

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

〇サンプルコード
%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, show_dots=False)
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

JupyterとPygalで折れ線グラフの点の大きさを変更する

折れ線グラフの点の大きさを変更するには、以下のサンプルのようにdots_sizeを使用します。

〇サンプルコード
%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, dots_size=10)
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