0

I'm using the following code in order to have an active plot:

pressure_fig= Figure(figsize=(11,6))
sensor_graph = pressure_fig.add_subplot(111)

x_vals = []
y_vals = []

sensor_graph.plot([], [])

canvas = FigureCanvasTkAgg(pressure_fig,graph_frame)
canvas.get_tk_widget().pack()
toolbar = NavigationToolbar2Tk(canvas, graph_frame)
toolbar.update()
canvas._tkcanvas.pack(anchor='w')

Which gives me this image. As you can see, the Legend is partially cut off and there is a bit of gray space on the side. However, when I attempt to increase the figure size to pressure_fig= Figure(figsize=(12,6)), I get the same problem. I also tried, when packing it onto the screen, using canvas.get_tk_widget().pack(fill=tk.BOTH), but this results in the same thing as using a 12x6 figure. Is there a way to force the plot to not be in the center of the canvas?

  • Check [How to put the legend out of the plot](https://stackoverflow.com/a/43439132/4124317). – ImportanceOfBeingErnest Feb 25 '20 at 17:14
  • That's what I had been referencing and it didn't help unfortunately – Daniel Mayper Feb 25 '20 at 17:35
  • There is no attempt shown in the question, so one cannot guess what you did wrong. – ImportanceOfBeingErnest Feb 25 '20 at 17:37
  • Try `canvas.get_tk_widget().pack(ipadx=100)`. You can adjust the value to fit your case. Also is `canvas._tkcanvas.pack(...)` redundant? – acw1668 Feb 26 '20 at 04:01
  • Or you can use `sensor_graph.legend(loc='best')` to let matplotlib to choose the best position for the legend. – acw1668 Feb 26 '20 at 04:09
  • @acw1668 It's a live plot so using `loc='best'` has the potential to have the legend hop all around. As for `canvas._tkcanvas.pack(...)` being redundant, I'm not entirely sure, I was following another thread's lead on how to embed the graph so I just threw it in there – Daniel Mayper Feb 26 '20 at 18:26

0 Answers0