Saved Matplotlib plot not displayed or detected
According to the Repl.it documentation it’s possible to save a Matplotlib plot to a file from Python with code such as
plt.savefig('plot.png') so that the environment detects the file and displays it in a preview pane. However, this doesn’t seem to work with other Matplotlib-based libraries such as Poliastro.
Poliastro is an astrodynamics Python package that uses Matplotlib’s plotting features. In a fresh Python 3 REPL I install Poliastro from the package manager. Then I evaluate in the REPL the following lines of code on the home page of Poliastro’s documentation site, one after the other:
Finally I evaluate:
From the shell I can see the saved
molniya.png plot file with
However, the plot is not displayed in a preview pane and the file is missing from the file tree, which doesn’t make it possible to save it locally or otherwise export it from Repl.it.
What am I doing wrong? Is this a Repl.it issue?
I did other tests and the preview pane showed up once more. I tried various combinations of removing
plt.ion(), turning off interactive mode in Matplotlib with
plt.ioff(), and referencing the plot file in the shell. But there was no apparent colletation.
I've played with the code and the REPL a bit more and it looks like Repl.it can indeed show the preview pane. First off, this expression is not needed as it just tells Matplotlib to show the plot immediately, which Repl.it can't do anyway:
At some point the preview pane did appear displaying the plot and the file appeared in the filetree. But there didn't seem to be any correlation with what I was doing, mostly waiting.
In a new REPL I opened the shell and tried to access the plot file with commands such as
file molniya.png, and
touch molniya.png but the preview pane didn't show up no matter what I did. Repl.it is apparently not continuously monitoring for new files being added or changed.
By the way, the only way I've found to close the preview pane is to delete the image file from the filetree. Is there a simpler way?
@PaoloAmoroso Hi, I find that the only way to consistently get the preview file to show up while using plt.savefig is by changing the main.py. For example: add a comment to the main.py. I don't know why it has to be that way but this is what the tutorial page says "The preview pane will appear whenever the file has been changed." I know it sounds stupid but I am new to this environment. And, I am waiting to hear a better as well.