Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run Plotly script from command line

I'm trying to run all cells of jupyter notebook from command line. For that task, I have done:

jupyter nbconvert --inplace --execute myNotebook.ipynb. 

The problem now is that my script contains some plots from Plotly library and then when I open the notebook again using jupyter's interface, plots are blanks. I have used many options like:

from plotly.offline import init_notebook_mode, iplot
init_notebook_mode(connected=True)

%matplotlib inline

¿Anyone has any idea for this problem?

Thanks

I add part of my script in order to help you.

import pandas as pd
import plotly
from plotly.offline import init_notebook_mode, iplot
import plotly.graph_objects as go
from datetime import datetime
init_notebook_mode(connected=True)

df = pd.DataFrame({'one' : pd.Series([10, 20, 30, 40]),'two' : pd.Series([10, 20, 30, 40])})

fig = go.Figure()
fig.add_trace(go.Scatter(x=df.one,y=df.two))
fig.update_layout(xaxis_range=[min(df.one),max(df.one)])
iplot(fig)

print(datetime.now())
like image 851
caumente Avatar asked Jul 12 '26 04:07

caumente


1 Answers

You can solve this problem with two step

  1. Your notebook is not trusted issue exists with plotly so trust your notebook

    jupyter trust myNotebook.ipynb

  2. Now run your notebook from command line

    jupyter nbconvert --inplace --execute myNotebook.ipynb.

You can also have a look at related

Here is my working notebook imageenter image description here

enter image description here

like image 155
nithin Avatar answered Jul 13 '26 18:07

nithin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!