-3

I can't understand the logic behind the 3rd line:

fig = plt.figure()
fig.suptitle("No axes in this figure", fontsize=12)
fig, ax_lst = plt.subplots(2, 2)

1st line: Plot the empty figure.

2nd line: Title.

3rd line: Put the graphs in the figure, but how? What's the logic? What means the comma there? (I know that a+b=11 if a,b=1+1,2+2+3

Chris
  • 2,019
  • 5
  • 22
  • 67
  • `Figure` and `axes` object. Refer here https://matplotlib.org/api/_as_gen/matplotlib.pyplot.subplots.html – meW Dec 07 '18 at 02:13

2 Answers2

1

In python, you can spread the elements of a tuple and assign each value of a variable.

c = (1, 2)
a, b = c
#a=1 b=2

print(a)
print(b)

In your example, the assignment just holds references to the objects. The function itself actually draws the plots.

Khanal
  • 788
  • 6
  • 14
1

plt.subplots adds a subplot to the current figure.

subplot(nrows, ncols, index, **kwargs)

The first arguments corresponds to the number of rows, the second one corresponds to the columns. This function will unpack to the tuple before the equal sign (fig, ax_lst).

This is a plt.subplot(2, 1) for example

Subplots