matplotlib.pyplot shows "old data" #667
-
What happened?If I try to plot "plain data" in pyplot (plt), the plot shows "old data" from spectrochempy NDDataset, too. Maybe it is related to inline plot configuration in Jupyter? I do not configure any special plotting options but spectrochempy seems to do so automatically when imported or plotting methode is called. The following picture shows the two plots I get. Surprisingly, they show the same contend and share the same consecutive figure number. What did you expect to happen?Since I configured two independent plots, I expect two seperated plots as output. Minimal Complete Verifiable Exampleimport spectrochempy as scp
from matplotlib import pyplot as plt
A = scp.NDDataset.linspace(1,100,50)
A = np.sqrt(A)
ax1 = A.plot()
plt.show()
plt.plot([0,10,20],[2,4,7])
plt.show() Relevant log outputNo response Anything else we need to know?No response EnvironmentINSTALLED VERSIONScommit: None |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
Actually, this is not a SpectroChemPy bug, but a matplotlib feature! To demonstrate I modified your example to use only matplotlib import numpy as np
from matplotlib import pyplot as plt
fig = plt.figure()
A = np.sqrt(np.linspace(1,100,50))
plt.plot(A)
plt.plot([0,10,20],[2,4,7])
plt.show() here you get a single figure with the two plot together: this is expected import numpy as np
from matplotlib import pyplot as plt
fig = plt.figure()
A = np.sqrt(np.linspace(1,100,50))
plt.plot(A)
plt.show()
plt.plot([0,10,20],[2,4,7])
plt.show() Here you get two time the same plot. import numpy as np
from matplotlib import pyplot as plt
fig = plt.figure()
A = np.sqrt(np.linspace(1,100,50))
plt.plot(A)
plt.show()
fig2 = plt.figure()
plt.plot([0,10,20],[2,4,7])
plt.show() Now you get to separate plot. So do not forget to instantiate a new figure for the second separate plot. SpectroChempy instantiates a new figure each time you use the Hope it helps. |
Beta Was this translation helpful? Give feedback.
-
That means there is now chance to use the implicite style of pyplot for quick drawings? |
Beta Was this translation helpful? Give feedback.
-
Not completely sure of what you mean about quick drawings, but I will try to answer. First instead of discussing on a closed issue, I will convert it to an open discussion, as the answers may be useful to other users. |
Beta Was this translation helpful? Give feedback.
-
SpectroChemPy uses matplotlib's explicit style by default (see https://www.spectrochempy.fr/latest/userguide/plotting/plotting.html for a detailed description - where unfortunately I've just seen that there are some warning problems - I'll look into this later). So we can write: With arguments to the plot method import spectrochempy as scp
A = scp.NDDataset(....something...)
ax = A.plot(xlim=(40,50))
scp.show() or with explicit style import spectrochempy as scp
A = scp.NDDataset(....something...)
ax = A.plot()
ax.set_xlim(40,50)
scp.show() or with the implicit style (which requires importing matplotlib.pyplot again, but this is done without any particular cost since scp has already imported the library) import spectrochempy as scp
A = scp.NDDataset(....something...)
ax = A.plot()
import matplolib.pyplot as plt
plt.xlim(40,50)
plt.show() You can also rewrite your own plot function using A |
Beta Was this translation helpful? Give feedback.
SpectroChemPy uses matplotlib's explicit style by default (see https://www.spectrochempy.fr/latest/userguide/plotting/plotting.html for a detailed description - where unfortunately I've just seen that there are some warning problems - I'll look into this later).
In fact, as the plot method returns a matplotlib Axe object, you can easily modify it using appropriate methods.
So we can write:
With arguments to the plot method
or with explicit style
or with the implicit style (which requ…