Issue
In a fresh Python install (Miniconda3, for details see below), Matplotlib 3.5.2 is not plotting as it used to:
Example 1
import numpy as np
import matplotlib.pyplot as plt
from math import pi
x = np.linspace(0, 1)
y1 = np.sin(2*pi*x)
y2 = np.cos(2*pi*x)
plt.plot(x, y1)
plt.plot(x, y2)
This gives me the first plot (x, y1), but not the second (x, y2)
Example 2
import numpy as np
import matplotlib.pyplot as plt
from math import pi
x = np.linspace(0, 1)
y1 = np.sin(2*pi*x)
y2 = np.cos(2*pi*x)
fig, ax = plt.subplots()
ax.plot(x, y1)
This doesn't plot anything at all, but only produces an empty plot.
In both cases, plt.show()
doesn't help. Also, I'm not getting any errors or warnings. Plotting both functions in one go (plt.plot(x, y1, x, y2)
) does work, by the way.
Installation details:
Ubuntu 20.04 LTS
Miniconda 3
Python 3.9.13
Spyder 5.3.1, with backend set to Automatic (opens plots in separate window)
Matplotlib 3.5.2
Both examples used to work just fine in my old install (Ubuntu 20.04, Miniconda 3, Python 3.7.12, Matplotlib 3.4.3, Spyder 5.1.5).
Does anyone know how to fix this?
EDIT:
- Also commands like
plt.xlim([0, 0.5])
do not have any effect - Running the first example script in one go, instead of line by line from the iPython console, does give the expected result (i.e. a blue sine and an orange cosine). This doesn't work for the second script though.
- After manually interacting with the plot window, e.g. by clicking in the plot area and pressing
g
(to toggle grid display), the most recent change to the plot suddenly appears, so it looks like something's wrong with the interaction between the iPython console and the plot window
Solution
It looks like my problem is related to Matplotlib 3.5.2. For now, I've downgraded to my previous Matplotlib version, 3.4.3.
Answered By - Sita
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.