Computer >> Computer tutorials >  >> Programming >> Python

How do you get the current figure number in Python's Matplotlib?


To get the current figure number in Python's Matplotlib, we can use plt.gcf().number.

Steps

  • Using figure(count) method, we can create a number of figures with count or windows name.
  • To get the count of figures, use plt.gcf().number.

Example

from matplotlib import pyplot as plt
fig = plt.figure(3)
print("Number of figures: ", plt.gcf().number)

Output

Number of figures: 3