LoginSignup
0
6

More than 3 years have passed since last update.

jupyter_notebookでグラフをHTML保存する方法

Posted at

よく忘れるので備忘録。

インタラクティブプロットツールcufflinksplotlyをインポートする。

package_import
import cufflinks  # df.iplotを使うため
import plotly
plotly.offline.init_notebook_mode(connected=False)

何かしらのグラフをノートブック上にプロットする。

HTMLをエクスポートしたいだけだったらこの手順は省略

ノートブックにプロット
# グラフ描画のセッティング
setting = dict(title='グラフの上のタイトル',
               colors=['purple', 'red', 'green', 'blue'],
               xTitle='横軸',
               yTitle='縦軸',
               legend='top',
               width=0.3,
               )
df.iplot(**setting)

HTMLとしてエクスポート

# HTML化
setting['asFigure'] = True  # dictオブジェクトにするために必要?
fig = df.iplot(**setting)
plotly.offline.plot(fig, filename='graph.html')  # ファイル名
0
6
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
6