#!/usr/bin/env python # coding: utf-8 # ## 4.5 グラフを画像ファイルに出力 # Colaboratoryを使う場合には次のセルのコメントを外して(Ctrl+/)実行します # In[ ]: # !pip install plotly==4.10.0 # !wget https://github.com/plotly/orca/releases/download/v1.2.1/orca-1.2.1-x86_64.AppImage -O /usr/local/bin/orca # !chmod +x /usr/local/bin/orca # !apt-get install xvfb libgtk2.0-0 libgconf-2-4 # In[1]: import plotly.graph_objects as go fig = go.Figure([go.Scatter(x=[1, 2, 3], y=[5, 3, 2])]) fig.write_image("fig1.png") # In[2]: from IPython.display import Image img_bytes = fig.to_image(format="png") Image(img_bytes)