0

When I am using iPython with plotly, plotly will show a graph for each application of fig.update_layout, fig.update_xaxes, etc. Consider the following:

import plotly.graph_objects as go
import numpy as np

time = np.linspace(0, 1, 100)
data1 = np.cos(time)
data2 = np.sin(time)

fig = go.Figure(
   [go.Scatter(x=time, y=data1),
    go.Scatter(x=time, y=data2)])

fig.update_layout(title_text='title')  # 1

fig.update_xaxes(title_text='x-axis')  # 2

fig.update_yaxes(title_text='y-axis')  # 3

fig.show()  # 4

If I run this code by calling :! python3 file.py, then the code runs fine and only one plot appears.

But if I run the code line by line using iPython then a plot will pop up for 1, 2, 3 and 4 above. So 4 plots in total. How can I suppress plots 1, 2 and 3 and just show the final plot at 4?

Edit:

I dont' think the suggested post answers my question. I am not using a Jupyter notebook. I am using neovim to write the code and then use tmux and slime to send the code to the Ipython terminal. None of the suggestions from the duplicate question worked.

alpastor
  • 199
  • 6
  • My apologies, the dupe target wasn't correct. I've just updated the close reason. I've verified that [this](https://stackoverflow.com/a/31792131/17769815) answer works using your code. – BrokenBenchmark Dec 28 '22 at 23:19
  • @BrokenBenchmark ah that makes sense to assign an unused variable, thank you! – alpastor Dec 28 '22 at 23:25

0 Answers0