0

I want to change the background color of the embeded matplotlob graph. I already got it to change the background color of the widget, but not of the chart (inside)I mean the white part of the program

here is the code:

from tkinter import *
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg

x = [1, 2, 3, 4, 5]
y = [1, 2, 3, 4, 5]

root = Tk()
root.title("graph embed")
root.geometry("200x300")
root.configure(bg="yellow")

ax = plt.gca()
ax.set_facecolor('yellow')
fig = plt.Figure(figsize=(5, 4), dpi=100)
fig.add_subplot(111).plot(x, y, "bo")
fig.set_facecolor("yellow")

chart = FigureCanvasTkAgg(fig, root)
chart.get_tk_widget().pack()

root.mainloop()
3
  • fig.add_subplot(111).plot(x, y, "bo", color="red") Commented Jul 20, 2020 at 13:21
  • I mean the white box around the points, not the color of the point Commented Jul 20, 2020 at 13:26
  • stackoverflow.com/a/23313630/5202279 Commented Jul 20, 2020 at 13:28

1 Answer 1

5

You are creating two separe axes and changing the facecolor on the wrong one. Try this:

(...)
root.configure(bg="yellow")

fig = plt.Figure(figsize=(5, 4), dpi=100)
ax = fig.add_subplot(111)
ax.plot(x, y, "bo")
fig.set_facecolor("yellow")
ax.set_facecolor('yellow')

chart = FigureCanvasTkAgg(fig, root)
(...)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.