0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Pythonのガントチャート生成ライブラリeleganttでGoogle Colab上にガントチャートを描く

Last updated at Posted at 2024-05-27

追記:もっと楽に書けるという記事を書きました


eleganttというガンチャート生成ライブラリがありますが、これを使ってGoogle Colab上でガントチャートを書くためにはコツが必要ですので、ちょっとポイントを書いておきます。

まず、ライブラリのインストールと同時にフォントもインストールしておく必要があります。こちらは公式のREADMEにも書いてある通り。

!pip install elegantt
!apt install fonts-noto-cjk

それから、公式READMEではpng形式でファイル名を指定して保存していましたが、eleganttはPIL/Pillowと同じ形式ですので、IPythonを使ってインラインで画像が表示できます。

from IPython.display import display
import elegantt

# Define chart properties
chartsize = (720,320)
bgcolor = (255,255,255)

# Create a Gant chart object
gchart = elegantt.EleGantt( chartsize, bgcolor, today="2019-10-15")

# Draw calendar and campains
gchart.draw_calendar()
gchart.draw_campain("2019-10-15","2019-10-18","Task 1")
gchart.draw_campain("2019-10-20","2019-10-23","Task 2")
gchart.draw_campain("2019-10-24","2019-10-30","Task 3")

display(gchart.im)

eleganttの0.0.5からはMermaid書式にも対応してるので、こういった書き方もできます。

s = """
task a            :done,    des1, 2024-05-15,2024-05-18
task b            :active,  des2, 2024-05-20, 4d
task c            :         des3, after des2, 7d
"""

gchart = elegantt.EleGantt()
parsed_events = gchart.parse_mermaid(s)
gchart.auto_resize(parsed_events)
gchart.draw_calendar()
for event in parsed_events:
    start = event["start"].strftime("%Y-%m-%d") if event["start"] else None
    end = event["end"].strftime("%Y-%m-%d") if event["end"] else None
    gchart.draw_campain(start,end,event["title"])
display(gchart.im)

追記:もっと楽に書けるという記事を書きました

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?