[PYTHON] Check the drawing result using Plotly by embedding CodePen in Qiita

To embed CodePen below, write the code in Python, convert and output it to HTML using the conversion function of plotly, paste it into CodePen to generate HTML for embedding, and paste it into Qiita to draw.

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

Please refer to the following URL for the work of pasting into CodePen and generating HTML for embedding. Qiita-You can now embed CodePen in articles with Qiita

The code below is written in Python that converts and outputs to HTML using the conversion function of plotly. This code has been confirmed to work only with Google Colabrator.

I have shared the code I actually wrote, so feel free to use it. 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")

Recommended Posts

Check the drawing result using Plotly by embedding CodePen in Qiita
Use the vector learned by word2vec in the Embedding layer of LSTM
Check if the password hash generated by PHP matches in Python
Feature extraction by TF method using the result of morphological analysis
Check the return value using PEP 380
Check the data summary in CASTable
Try to build a pipeline to store the result in Bigquery by hitting the Youtube API regularly using Cloud Composer