Ask Your Question
1

Using pyplot to plot and continue to work in terminal

asked 2022-04-03 09:33:55 +0100

mcmug gravatar image

I use pyplot to visualize data in sagemath. But each time I plot, I have to close the window of the plot to be able to enter another command in sagemath terminal. What should I add in my code in order to be able to continue to work with sagemath without having to close the window of plot? Thanks in advance!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2022-04-03 18:19:12 +0100

Emmanuel Charpentier gravatar image

I suppose that you are doing something like :

import matplotlib.pyplot as plt
myplot = plt.plot(yadda, yadda, yadda)
plt.show(myplot)

The help for plt.show (available by typing plt.show?) states, among other not unintersing things :

Signature:      plt.show(*, block=None)
Docstring:     
   Display all open figures.

   block : bool, optional
      Whether to wait for all figures to be closed before returning.

      If True block and run the GUI main loop until all figure windows
      are closed.

      If False ensure that all figure windows are displayed and return
      immediately.  In this case, you are responsible for ensuring
      that the event loop is running to have responsive figures.

      Defaults to True in non-interactive mode and to False in
      interactive mode (see .pyplot.isinteractive).

   ion : Enable interactive mode, which shows / updates the figure
   after
      every plotting command, so that calling "show()" is not
      necessary.

   ioff : Disable interactive mode. savefig : Save the figure to an
   image file instead of showing it on screen.

Is that illumination enough ?

edit flag offensive delete link more

Comments

Note that Sage's graphics aren't half bad for "mathematical" plotting. Try comparing Sage's and matplotlib's results for your use cases...

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2022-04-03 18:32:39 +0100 )edit

Thanks! It worked! For the moment I just need to draw some points on the screen.

mcmug gravatar imagemcmug ( 2022-04-04 03:37:58 +0100 )edit

But when I plot again, the new plot is added in the same window. Is there a way to make it show in a new window?

mcmug gravatar imagemcmug ( 2022-04-04 04:49:43 +0100 )edit

Is there a way to make it show in a new window?

That's the behavior of Sage's plot and cousins...

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2022-04-04 10:08:26 +0100 )edit

Now I find that it is even better that plots are shown in the same picture.

mcmug gravatar imagemcmug ( 2022-04-06 03:00:58 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2022-04-03 09:33:55 +0100

Seen: 329 times

Last updated: Apr 03 '22