Plot issue with Spyder 4

41 views
Skip to first unread message

DrBwts

unread,
Aug 14, 2020, 6:38:40 AM8/14/20
to spyder

I'm using the following code to make 2 plots,

import numpy as np
import matplotlib.pyplot as plt

x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
x1 = [1, 2, 3, 4, 5]
y1 = [1, 4, 9, 14, 25]
t = np.arange(0.0, 2.0, 0.01)
s1 = np.sin(2*np.pi*t)
s2 = np.sin(4*np.pi*t)

plt.figure(1)
plt.subplot(111)
plt.plot(x, y)
plt.subplots(112)
plt.plot(x1, y1)

plt.figure(2)
plt.subplot(211)
plt.plot(t, s1)
plt.subplot(212)
plt.plot(t, 2*s1)

plt.show()

The first plot is fine but the second plot gets messed up,

messedUpPlotSpyder.png

But when I comment out the code for the 1st plot it plots as exected,

notMessedUpPlotSpyder.png

Aldo Raine

unread,
Aug 14, 2020, 1:03:27 PM8/14/20
to spyder
If you want the stacked plot as in the second case, the subplot call needs to be 211 or 212.  The first 2 digits define the rows and columns of your plot "grid".
This is a matplotlib usage issue not related to Spyder.  

Aldo Raine

unread,
Aug 14, 2020, 1:03:28 PM8/14/20
to spyder
Also, "plt.subplots(112)" should be plt.subplot(212)

On Friday, August 14, 2020 at 6:38:40 AM UTC-4 drb...@gmail.com wrote:
Reply all
Reply to author
Forward
0 new messages