First time here? Check out the FAQ!

Ask Your Question
1

Using pyplot to plot and continue to work in terminal

asked 2 years ago

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!

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
2

answered 2 years ago

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 ?

Preview: (hide)
link

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 ( 2 years ago )

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

mcmug gravatar imagemcmug ( 2 years ago )

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 ( 2 years ago )

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 ( 2 years ago )

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

mcmug gravatar imagemcmug ( 2 years ago )

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: 2 years ago

Seen: 383 times

Last updated: Apr 03 '22