0

I have 2 figures in matplotlib, one is a standard graph the other is a Basemap that Im plotting lat/long onto. Im trying to set a logo for both windows, but I can only get the custom logo onto Figure1, Figure2 still shows Tkinter logo.

Im following one of the answers from here Change icon in a Matplotlib figure window

from Tkinter import PhotoImage
import matplotlib as mpl
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
import numpy as np

thismanager = plt.get_current_fig_manager()
img = PhotoImage(file='elcc_logo.ppm')

I have 2 plots:

plt.figure(num=1, figsize=(16, 12))
thismanager.window.tk.call('wm', 'iconphoto', thismanager.window._w, img)
plt.plot(date, energyplot, 'bo')

plt.figure(num=2, figsize=(10, 8))
thismanager.window.tk.call('wm', 'iconphoto', thismanager.window._w, img)
earth = Basemap(projection='mill')
earth.drawcoastlines(color='0.50', linewidth=0.25)
earth.fillcontinents(color='0.95', zorder=0)
x, y = earth(longitudes, latitudes)
earth.scatter(x, y, color='g', marker='o', linewidths=0.5)
for i, txt in enumerate(datalogger_id):
        plt.annotate(txt, xy=(x[i], y[i]), xycoords='data', xytext=(8, -4), textcoords='offset points', clip_on=True)
plt.show()

I can swap the figure number and whichever one has num=1 gets the logo, I just cant get it on both at the same time.

Scalextrix
  • 501
  • 2
  • 10
  • 24
  • The code you are using is not clear. At which point is plt.figure sitting compared to the part which adds the picture? In any case you will of course need to give both figures the logo, not only one of them. – ImportanceOfBeingErnest Sep 20 '17 at 17:30
  • I have tried many arrangments, I have put thismanager.window.tk.call('wm', 'iconphoto', thismanager.window._w, img) before each plt.figure, and after, at the top of the script, and immediately before plt.show(). I could list them all out, or someone could tell me how to do it properly – Scalextrix Sep 20 '17 at 17:38
  • You need `thismanager` and `thismanager2`, one for each figure. I cannot show you how to do it properly if you don't provide at least one [mcve] of the issue. – ImportanceOfBeingErnest Sep 20 '17 at 17:40
  • I dont know what completeness is for this problem, I have been downvoted before for giving irrelevant code. When you dont know, its very hard to know. I edited to give one of the many variations I have tried. – Scalextrix Sep 20 '17 at 17:49
  • To check if you have provided a [mcve] or not, is pretty easy. You copy the code from the question to a python file and run it. If it reproduces the issue, it is already a complete and verifiable example. If you are able to delete further lines from the code or make it less complex, then it hasn't yet been minimal. When I try to run your code, I get `RuntimeError: Too early to create image` – ImportanceOfBeingErnest Sep 20 '17 at 17:58

1 Answers1

0

I would try the following (unfortunately I cannot test it, because I don't have any icon file available), where you create one manager per figure.

import matplotlib; matplotlib.use("TkAgg")
from Tkinter import PhotoImage
import matplotlib as mpl
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
import numpy as np

plt.figure(num=1, figsize=(16, 12))
thismanager = plt.get_current_fig_manager()
img = PhotoImage(name="icon.ppm")
thismanager.window.tk.call('wm', 'iconphoto', thismanager.window._w, img)

plt.figure(num=2, figsize=(10, 8))
thismanager2 = plt.get_current_fig_manager()
img2 = PhotoImage(name="icon.ppm")
thismanager2.window.tk.call('wm', 'iconphoto', thismanager2.window._w, img2)

plt.show()
ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
  • 1
    Im now getting this error:thismanager2.window.tk.call('wm', 'iconphoto', thismanager2.window._w, img2) _tkinter.TclError: can't use "pyimage20" as iconphoto: not a photo image – Scalextrix Sep 21 '17 at 07:34
  • I tried making 2 different .ppm files like icon1.ppm icon2.ppm but its not made any differnce – Scalextrix Sep 21 '17 at 07:35
  • That is unfortunate. But on the other hand this would be a [mcve] you can ask a question about, either by editing your question or asking a new one. – ImportanceOfBeingErnest Sep 21 '17 at 09:20