7
4

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.

Plotlyを使った描画結果をQiita内にCodePen埋め込むことで確認する

Last updated at Posted at 2019-12-31

下記のCodePenの埋め込みは、Pythonでコードを書きplotlyの変換機能を使ってHTMLに変換・出力し、それをCodePenに貼り付けて埋め込み用のHTMLを生成しQiitaに貼り付けて描画しています。

See the Pen qiita_embed_sample by wakame1367 (@wakamezake) on CodePen.

CodePenに貼り付けて埋め込み用のHTMLを生成するという作業は下記URLを参照してください。
Qiita - Qiitaで記事にCodePenが埋め込めるようになりました

下記コードはplotlyの変換機能を使ってHTMLに変換・出力するコードをPythonで書いています。
このコードについてはGoogleColabratoryでのみ動作確認しております。

実際に書いたコードを共有状態にしておきましたのでご自由にお使いください。
GoogleClolabratory - plotly_to_html

plotly_to_html.py
#Plotly
import plotly
import plotly.tools as tls
import plotly.graph_objs as go
import plotly.express as px
import plotly.figure_factory as ff

# If you're using this code locally:
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot

# If you're copying this into a jupyter notebook, add:
init_notebook_mode(connected=True)

# To run Plotly code in colab:
import plotly.io as pio
### REMOVE THIS LINE BEFORE RUNNING IN A JUPYTER NOTEBOOK
pio.renderers.default = 'colab'

fig = {
    "data": [plotly.graph_objs.Scatter(x=[1, 2, 3], y=[10, 20, 30])],
    "layout": plotly.graph_objs.Layout(title="offline plot"),
}

plotly.offline.plot(fig, auto_open=False, filename="temp-plot.html", include_plotlyjs="cdn")
7
4
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
7
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?