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 3 years have passed since last update.

JupyterLabでdotファイルを表示する

Posted at

機械学習実装練習中にJupyterLab上でdotファイルをpngファイルに変換して表示したかったので全手順をメモしておきます。

手順

  1. pipのインストール
  2. pydotplus、graphvizのインストール
  3. JupyterLabにバインド
  4. dotファイルの変換と表示をする関数を作成
  5. 表示処理の実施

pipのインストール

この辺を参考に。。。

pydotplus、graphbizのインストール

以下のコマンドを実行

$ pip install pydotplus
$ pip install graphbiz

JupyterLabにバインド

grahvizをJupyterLabで利用できるようにバインドする

$ conda install -c conda-forge python-graphviz

dotファイルの変換と表示をする関数を作成

JupyterLab上で以下を記述

import os
import pydotplus
from IPython.display import Image,display_png

PROJECT_ROOT_DIR = "."

def image_path(fig_id):
    return os.path.join(PROJECT_ROOT_DIR, "images", fig_id)
def view_dot(fig_id):
    file_full_path=PROJECT_ROOT_DIR+"/images"
    graph = pydotplus.graphviz.graph_from_dot_file(file_full_path+"/"+fig_id)
    graph.write_png(file_full_path+"/"+fig_id+'.png')
    display_png(Image(graph.create_png()))

表示処理の実施

JupyterLab上で対象のdotファイルを表示させます。

view_dot("ファイル名.dot")

まとめ

バインド処理がそこそこ時間がかかりますのでコーヒーでもいただきながら待ちましょう。

参考

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?