Using figure number as text and edit

I have been changing matplotlib figure number to text strings and would like to subsequently add to that string later to display some stays info. Can’t seem to find a way that works, can anyone suggest a way to do this?

The idea is to be able to stack plots on screen like index cards with only the figure num text exposed for picking.

What about this?

num = 12
newnum = int(str(num) + '13')
print(newnum)

If you want to add letters or spaces or non-numeric characters to newnum it has to stay a string.

num = 12
newnum = str(num) + ',13'
print(newnum)

Thanks Chuck. Here is some code that better illustrates what I am trying to do (sorry about the indentation, did not figure that out…)

create the figures with replacements for the num

figs = []
x,y = 100,100
for i in 0,1,2,3,4:
    fig = plt.figure(num=f'P1105{str(i)}')
    print(fig._label)
    figs.append(plt.figure(num=f'P1105{str(i)}'))
    fig.canvas.manager.window.setGeometry(x, y+i*25, 300, 100)

# attempt to edit the figure labels
for i in 0,1,2,3,4:
    fig = plt.figure(f'P1105{str(i)}')
    print('original _label is {fig._label}')
    # update figure reference  num, special variable _label, and redraw
    fig._label = f'new _label is P1105{str(i)} for figure {i}'
    print(fig._label)
    fig.canvas.manager.set_window_title(fig._label)
    fig.canvas.draw()

To display code properly you can wrap it in triple backticks (```). The forum UI has a button </> that will do this for you: select the code, click the button, and it’ll display properly.

Regarding your question, it’s been a long while since I worked with individual matplotlib windows like this[1]. Searching around a bit, have you tried this:

fig.canvas.manager.set_window_title('New Figure Name')

Unclear if that will work though. edit: I had a typo (missing manager) but this worked for me with TkAgg on MacOS


  1. maybe never? ↩︎

Yes, that works, James. Thanks for that

Regards, Tim

James, here’s what the output looks like now, exactly as I wanted it

1 Like