【问题标题】:change background color of matplotlib graph [duplicate]更改matplotlib图的背景颜色[重复]
【发布时间】:2020-07-20 13:15:51
【问题描述】:

我想更改嵌入式 matplotlob 图形的背景颜色。我已经得到它来改变小部件的背景颜色,但不是图表(内部)I mean the white part of the program

代码如下:

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()

【问题讨论】:

标签: python matplotlib tkinter


【解决方案1】:

您正在创建两个单独的轴并在错误的轴上更改 facecolor。试试这个:

(...)
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)
(...)

【讨论】:

    猜你喜欢
    • 2016-03-05
    • 2014-10-04
    • 2019-06-29
    • 1970-01-01
    • 2021-09-30
    • 1970-01-01
    • 2014-08-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多