0

In my code, I have it so that first images are plotted and then the user is asked to choose an image.

But when I run the cell, the user is first asked to choose an image and then the images are plotted. Not sure why.

Code in this picture:enter image description here

srv_77
  • 547
  • 1
  • 8
  • 20

1 Answers1

0

Jupyter will render the plot after everthing else if it is running in 'inline' mode. I can't reproduce what you have exactly but take the following example:

import numpy as np
import matplotlib.pyplot as plt


x = np.linspace(0,10,10)
y = 5*x +2


plt.plot(x,y)
print('Text is here first even though the plot call comes last')

The output of this looks like:

Plot example without inline

So the plot is rendered last. Instead if we add '%matplotlib notebook' to the start. The plot will be rendered interactively and before the text. If you want to switch back just change it to '%matplotlib inline'. There are a number of other backend plotting options that are worth exploring.

Ross Gray
  • 1
  • 1
  • I tried doing that but it still happens in the reverse order and I also get this error "Javascript error: IPython is not defined" – srv_77 Feb 19 '21 at 04:49
  • This should help: https://stackoverflow.com/questions/51922480/javascript-error-ipython-is-not-defined-in-jupyterlab – Ross Gray Feb 19 '21 at 06:25