Python Tkinter: set label background (in a canvas) to transparent - python

I'm trying to make a graph using tkinter and I want to have a monthly profit label situated above the point on the graph at which this profit is situated.
The problem I am having is the white background of the label is clipping off the lines in the line graph. Is there any way to set the label background to transparent?
I have tried calling the labels before I make the lines however the label is still on top of the lines when I did that.

Related

Matplotlib Glitches After Window Resize using Blitting

I am trying to use blitting with matplotlib to improve the performance of my plot, but am running into glitches after resizing the matplotlib window.
I have a matplotlib window showing 8 different lines plotted, along with a table of the values from the plot. The table and plot are updated every ~0.7 seconds.
Here is my main loop:
canvas.draw()
background = canvas.copy_from_bbox(ax.bbox)
while True
canvas.restore_region(background)
[update data for lines, table]
for line in lines:
ax.draw_artist(line)
canvas.blit(ax.bbox)
for line in lines:
line.set_animated(False)
canvas.draw_idle()
canvas.flush_events()
for line in lines:
line.set_animated(True)
time.sleep(0.7)
This updates as I expect it to, and everything looks OK.
But then when I resize the plot window (by clicking and dragging the window edge) I start to see artifacts left over from apparently as the resize was occurring (it appears for maybe 0.1 second, so I can't attach a screenshot). Basically I see what appears to be an old plot and the border of my table for a very short time on each iteration through my main loop, then the plot and table display fine.
What I've Tried:
I registered a callback for 'resize_event' and in that case do:
canvas.restore_region(firstBackground)
canvas.draw_idle()
canvas.flush_events()
Then on the next iteration through the main loop behave like normal. My callback is running, but this doesn't seem to help the problem at all.
So I think I need to do a transform on the background I saved before any data was plotted and call restore_region with the transformed background, but I am not sure if I am missing something simple.
EDIT:
Some more information. The plot I am trying to blit has two axes in the same area(one was created by calling twinx() on the other axis)
So far I have tried:
Calling set_visible(False) on all lines, then drawing and getting a new background image. This shows the same glitch on resize.
Calling cla() on the two axes that overlap. This also shows the same glitch after resizing.

How to add subplot in python use matplotlib

I have a canvas to draw my figure in python and matplotlib
i want to add plot to that canvas dynamically
in fact i want to area of convas share bitwen all child plot
for example if canvas have only one plot, all area of canvas alocated to this and if add another plot to that canvas all area of canvas shared bitwen this tow plot and ...
Note: I do not know in advance how many plot(charts) I am going to add to canvas
thank you

contour plot matplotlib on a specific background color

I am generating contour plots (with transparent background) for pH of water on a river, and am overlaying the generated plot on the interactive map using map box. It looks like this:
I want to overlay plot in only on the water area, and not show over the ground area.
In my understanding there should be two ways possible:
1. While generating the image, making that part invisible
2. While overlaying the image, making that part invisible
I have tried finding solution for both but couldn't get a solution. Is there any way to go about it?

Showing Matplotlib graphs in a canvas tkinter python 2.7

i want to display a graph in a canvas. The GUI was written in tkinter using python 2.7.
self.plotting(x, pa, y)
savefig("Omegakillerisawesome.png")
im=PhotoImage(file="Omegakillerisawesome.png")
self.canvasForGraph.create_image(500, 350, anchor=CENTER, image=im)
#show()
os.remove('Omegakillerisawesome.png')
The plotting function was implemented by me. accepting x,y values. so i'm hoping to show the graph in a canvas. so i'm saving the graph in the directory and reloading the image to the canvas. The problem is the .png file is not appearing in the canvas.
but if i uncomment the show() function the image comes up in the canvas as well as the usual window that graphs are displayed. i don't want that. i only want the graph to show up in the canvas.
please help. i'm a newbie.
[edit]
depth=[1,2,3,4,5,6]
temp=[9,8,7,6,5,4]
plot(depth,temp)
show()
this shows me a frame with my graph in it. but i want to do is display the graph inside a canvas widget using tkinter. but i dont want the usual frame that comes with the latter code. i just want the graph plotted inside the canvas no more.
that is what i'm trying to achieve from the first piece of code.
thanks.

Possible to create single pixel wide horizontal/vertical ttk.Separator's?

Is there a way to create single pixel wide horizontal and vertical ttk.Separator()'s?
Python 2.7/Windows: When I magnify the ttk Separators they are built as 2 parallel lines - one line gray and one line a light/white color. The latter color added to create a subtle 3d effect?
I would like to create single pixel wide separators that have the system default gray color. A bonus would be the ability to programmatically discover the system color used for a separator's gray band.
If you need a single pixel line, create a normal frame with a width of 1. It will have the default gray background. If you want the background of the root window you can always just ask:
import Tkinter as tk
root = tk.Tk()
print "background is", root["background"]

Categories

Resources