2

I would like to combine two images in a single GUI, but I want the combining to happen after I click a button. I'm using a grid structure to format the GUI, and employing Tkinter. The image is imported and placed using:

label2 = ttk.Label(tab2)
image2 = PhotoImage(file="worldna.gif")
label2['image'] = image2
label2.grid(column=0, row=0, columnspan=4)

Some database processing is done, and when I press a button, I get a contour plot. The contour is built using 3 vectors -- lat, lon, and data:

x = avglon; y = avglat; z = avgmeas
# Set up a regular grid of interpolation points
xi, yi = np.linspace(x.min(), x.max(), 150), np.linspace(y.min(), y.max(), 150)
xi, yi = np.meshgrid(xi, yi)
# Interpolate
rbf = scipy.interpolate.Rbf(x, y, z, function='cubic')
zi = rbf(xi, yi)
plt.imshow(zi, vmin=z.min(), vmax=z.max(), origin='lower',
           extent=[x.min (), x.max(), y.min(), y.max()])
plt.set_adjustable('box-forced')           # Eliminate white space around  image
plt.scatter(x, y, c=z)
plt.show()

I would like to apply a 60% transparency to the interpolated scatter plot, and overlay it onto "worldna.gif". Any suggestions would be appreciated!

AaronJPung
  • 1,105
  • 1
  • 19
  • 35
  • Duplicate of multiple SO questions. Search `[tkinter] image transparency`. I selected the first response to that query, which has two answers. Summary: tk does not compose images; use external package, such as `pillow`. – Terry Jan Reedy Feb 22 '16 at 21:52
  • I think my question is still relevant. I'm trying to plot contour data over an image, not overlap two images -- the data is never saved or loaded as an image. I understand your response regarding composing images, but this was not my question. – AaronJPung Feb 22 '16 at 22:00
  • I marked as duplicate because you specified transparency processing, which tk does not do. For that I believe you will have to turn the plot into an external image. You could try to semi-simulate blending with dots and lines over an image. What I am not sure about is whether the white space of dotted lines will be white or let a background image show. If the former, you could plot lines as individual dots, but I expect that the dots would be solid colors and not blended with the backgound. Using pillow for true blending seems easier. – Terry Jan Reedy Feb 22 '16 at 22:09
  • @TerryJanReedy, Thank you for your input -- is there another method that I may not be thinking of, to overlay data on top of an image? The image is a satellite image of the earth. It's tempting to use `basemap` for this, but they do not provide the realistic imagery I am looking for. – AaronJPung Feb 22 '16 at 22:11
  • I suppose this is what you are looking for http://stackoverflow.com/questions/5073386/how-do-you-directly-overlay-a-scatter-plot-on-top-of-a-jpg-image-in-matplotlib#5073509 – R4PH43L Feb 23 '16 at 13:51

0 Answers0