chartyを使ってみる

モチベーション

前提

chartyを使う

mfham@mac ~/w/charty> pwd
/Users/mfham/work/charty

# pyenv(https://github.com/pyenv/pyenv)導入
mfham@mac ~/w/charty> brew install pyenv

# pyenvのREADME.mdに記載の「Basic GitHub Checkout」の「2. Configure your shell's environment for Pyenv」の手順をやる
# 私の場合fishの手順を実行

# pythonインストール(chartyのREADME.mdも見ながら)
mfham@mac ~/w/charty> CONFIGURE_OPTS="--enable-shared" pyenv install 3.9.7

# matplotlibインストール
mfham@mac ~/w/charty> pip3 install matplotlib
# サンプルプログラム作成(README.mdに記載のサンプルを一部改変)
require "charty"

charty = Charty::Plotter.new(:pyplot)

#days = [Date.new(2021, 9, 24), Date.new(2021, 9, 25), Date.new(2021, 9, 26), Date.new(2021, 9, 27), Date.new(2021, 9, 28)]
days = ['2021/04', '2021/05', '2021/06', '2021/07', '2021/08']

bar = charty.bar do
  series days, [10,40,20,90,70], label: "sample1"
  range x: 0..10, y: 1..100
  xlabel 'foo'
  ylabel 'bar'
  title 'bar plot'
end
bar.render("sample_images/bar_pyplot.png")


# 実行
mfham@mac ~/w/charty> ls -l
total 24
-rw-r--r--  1 mfham  staff   64  9 29 00:21 Gemfile
-rw-r--r--  1 mfham  staff  937  9 29 00:47 Gemfile.lock
-rw-r--r--  1 mfham  staff  439  9 29 00:53 sample.rb
drwxr-xr-x  3 mfham  staff   96  9 29 00:47 vendor


mfham@mac ~/w/charty> ls -l
total 24
-rw-r--r--  1 mfham  staff   64  9 29 00:21 Gemfile
-rw-r--r--  1 mfham  staff  937  9 29 00:47 Gemfile.lock
-rw-r--r--  1 mfham  staff  439  9 29 00:53 sample.rb
drwxr-xr-x  3 mfham  staff   96  9 29 23:14 sample_images
drwxr-xr-x  3 mfham  staff   96  9 29 00:47 vendor
mfham@mac ~/w/charty> ls -l sample_images/
total 24
-rw-r--r--  1 mfham  staff  11722  9 29 23:14 bar_pyplot.png

f:id:mfham:20210929231616p:plain
sample

もっと使う

GitHub - mfham/sandbox_of_charty