This code only produces one figure with two plots on it
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
def squareX(x):
return x*x
fig,ax=plt.subplots()
i=np.arange(5)
j=squareX(i)
print(i,j)
figure0=plt.plot(i,j)
#plt.show()
#fig,ax=plt.subplots()# if you omit this then a new plot wont show-you therefore need to show the plot before
x = np.random.rand(10)
y = np.random.rand(10)
figure1 = plt.plot(x,y)
Question 1. The first call to
fig,ax=plt.subplots()
returns two variables that are never used. Rather, the two plots are made using
figure0 = plt.plot(x,y)
and
figure1 = plt.plot(x,y)
Why does matplotlib decide to output them both after the second call? What makes the first call to figure0 = plt.plot(x,y)
invisible until the end?
Question 2) If first commented line is UNCOMMENTED, then matplotlib displays two figures. I can understand that plt.show()
after the first call to figure0 = plt.plot(x,y)
causes matplotlib to draw a figure but there is no call to plt.show()
after the call to figure1 = plt.plot(x,y)
but figure1 still gets drawn.
Question 3) If the second commented line is UNCOMMENTED then matplotlib displays two figures. But still, the second uncommented line seems almost irrelevant as its variables are never used.
I realize this is a VERY BASIC question and refers to the 'underworkings'of matplotlib. Please forgive me if it has been CLEARLY addressed somewhere but there seems to be a lot of disconnected documentation about matplotlib. If you have a link for a simpleton like me I would appreciate it.