1

When creating a figure in matplotlib by plt.figure(num), num can be a number or a string.

I would like to obtain the string used for num.

As in here I can do plt.figure(3); plt.gcf().number => 3 but this does not work if num is a string.

How to get the string value?

(I am not asking about suptitle)

scrx2
  • 2,242
  • 1
  • 12
  • 17

1 Answers1

2

The figure label can be obtained via fig.get_label()

fig = plt.figure("ABCD")
print(fig.get_label())

If your figure does not have a label you can still get the number

if fig.get_label() == "":
    print(fig.number)
else:
    print(fig.get_label())
ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712