Python: グラフ作成の統合ライブラリ3 , PyViz

I.PyViz

 

PyVizはPythonのグラフ作成統合ライブラリです。いくつかのグラフ作成ライブラリを使いやすく統合したものです。

はじめて使用する場合は次を参考にインストールしてください。

 

グラフ作成の統合ライブラリ1

 

すでにインストールしている場合は次をターミナルで実行します。

1行目で、pyviz-tutorialの名の仮想環境に入ります。

2行目でpyviz-examplesのフォルダに移動します。

3行目で、Jupyter Notebookを起動します。

 

conda activate pyviz-tutorial
cd pyviz-examples
jupyter notebook 

 

II.データ

 

データフレームから単純なグラフを作成し、矢印とテキストを書き込みます。描画にはmatplotlibを使用します。

 

元のデータ

 

第1-(1)-3図 雇用者報酬の推移

 

加工したデータ

 

https://pastebin.com/raw/9HJmKJTC

 

III.テーブルとグラフ

 

 

IV.テキストと矢印をいれる

 

 

 

増加率のグラフです

 

 

#Import necessary libraries
import datashader
import dask
import geoviews
import bokeh
import pandas as pd
import holoviews as hv
import numpy as np
%matplotlib inline
hv.extension('matplotlib')

# read a sample data
dat0 = pd.read_csv('https://pastebin.com/raw/9HJmKJTC')
dat0.head()

# create a graph
compEmpNominal = dat0[["year","compEmpNominal"]].groupby("year").aggregate(np.sum)
compEmpNominal.plot()

# add arrows and texts
compEmpNominal_curve = hv.Curve(compEmpNominal, 'year', 'compEmpNominal')
annotations = hv.Arrow(2008, 1058, 'Lehman', 'v') * hv.Arrow(2014, 1040, '8 %', 'v')
compEmpNominal_curve * annotations

# create a graph
compEmpReal = dat0[["year","compEmpReal"]].groupby("year").aggregate(np.sum)
compEmpReal.plot()

# add arrows and texts
compEmpReal_curve = hv.Curve(compEmpReal, 'year', 'compEmpReal')
annotations = hv.Arrow(2008, 1015, 'Lehman', 'v') * hv.Arrow(2014, 1020, '8 %', 'v')
compEmpReal_curve * annotations

# create a graph
compEmpNominalGrowth = dat0[["year", "compEmpNominalGrowth"]].groupby("year").aggregate(np.sum)
compEmpNominalGrowth.plot()

# add arrows and texts
compEmpNominalGrowth_curve = hv.Curve(compEmpNominalGrowth, 'year', 'compEmpNominalGrowth')
annotations = hv.Arrow(2008, 0.001, 'Lehman', 'v') * hv.Arrow(2014, 0.02, '8 %', 'v')
compEmpNominalGrowth_curve * annotations

# create a graph
compEmpRealGrowth = dat0[["year", "compEmpRealGrowth"]].groupby("year").aggregate(np.sum)
compEmpRealGrowth.plot()

# add arrows and texts
compEmpRealGrowth_curve = hv.Curve(compEmpRealGrowth, 'year', 'compEmpRealGrowth')
annotations = hv.Arrow(2008, 0.001, 'Lehman', 'v') * hv.Arrow(2014, 0.00, '8 %', 'v')
compEmpRealGrowth_curve * annotations

 

Please follow and like us:

About shibatau

I was born and grown up in Kyoto. I studied western philosophy at the University and specialized in analytic philosophy, especially Ludwig Wittgenstein at the postgraduate school. I'm interested in new technology, especially machine learning and have been learning R language for two years and began to learn Python last summer. Listening toParamore, Sia, Amazarashi and MIyuki Nakajima. Favorite movies I've recently seen: "FREEHELD". Favorite actors and actresses: Anthony Hopkins, Denzel Washington, Ellen Page, Meryl Streep, Mia Wasikowska and Robert DeNiro. Favorite books: Fyodor Mikhailovich Dostoyevsky, "The Karamazov Brothers", Shinran, "Lamentations of Divergences". Favorite phrase: Salvation by Faith. Twitter: @shibatau

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.