You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I faced an issue regarding how to load a figure after pickling it. I don't know if this might be a bug (in VSCode), the very nature of the package or other things.
The saving process of the figure goes smoothly. Code for reference:
with open('cdImg.pickle', 'wb') as f:
pickle.dump(f1, f)
However, when I load the figure in Ipython with the following code:
In [1]: import pickle
In [2]: import matplotlib.pyplot as plt
In [3]: candleFig = pickle.load(open('cdImg.pickle', 'rb'))
In [4]: candleFig.show() ### Here plt.show() also works.
The image shows perfectly. Using that same code in VSCode (within the same env; hence, same python and package versions) I don't get the figure, but the program executes perfectly and without any error.
In contrast, if I execute the following in VSCode:
import pickle
import matplotlib.pyplot as plt
def loadImage():
candleFig = pickle.load(open('cdImg.pickle', 'rb'))
plt.show() ### In the IPython example it was: candleFig.show()
if __name__ == '__main__':
loadImage()
It loads the image perfectly. Notice the change from candleFig in ipython to plt.show() in VSCode.
¿Is there anything I'm missing about the candleFig.show() not working in VSCode?
Figure.show() is quite different from plt.show(); see e.g. #13101 (comment) For your use case you should use plt.show() in both situations.
Actually, the environments are not the same. VSCode runs the code in a simple python shell. Ipython does magic in the background. I don't know what exactly, but for sure it's responsible that Figure.show() works in an interactive shell as well.
The difference between Figure.show() and plt.show() should probably be documented better.
Many thanks for the comments. I will stick with the plt.show() option as it looks like (after reading the referenced comment) handles all the caveats for the end-user more easily.
In regard to the difference in environments, you are totally right. I tried to highlight that the versions were the same in both cases; but my comment was not totally correct technically speaking.
I could consider this as closed if you (or others) don't have anything else to add.
I faced an issue regarding how to load a figure after pickling it. I don't know if this might be a bug (in VSCode), the very nature of the package or other things.
The saving process of the figure goes smoothly. Code for reference:
However, when I load the figure in Ipython with the following code:
The image shows perfectly. Using that same code in VSCode (within the same env; hence, same python and package versions) I don't get the figure, but the program executes perfectly and without any error.
In contrast, if I execute the following in VSCode:
It loads the image perfectly. Notice the change from
candleFig
in ipython toplt.show()
in VSCode.¿Is there anything I'm missing about the candleFig.show() not working in VSCode?
Matplotlib version: 3.0.2
Python version: 3.6.8
Ipython: 6.4.0
Pickle version: 4.0
The text was updated successfully, but these errors were encountered: