问题内容 我正在尝试在图形中创建图例,但当我使用 legend() 时它不起作用。我不知道还能有什么。我看到了很多关于它的信息,我也在做同样的事情,但它一直不起作用。你能帮我一下吗?
我正在尝试在图形中创建图例,但当我使用 legend() 时它不起作用。我不知道还能有什么。我看到了很多关于它的信息,我也在做同样的事情,但它一直不起作用。你能帮我一下吗?
在我的代码下面:
import tkinter as tk
import matplotlib.pyplot as plt
from matplotlib.figure import Figure
from matplotlib.backends.backend_tkagg import FigurecanvasTkAgg
from matplotlib import animation
import random
# Create the Tkinter window
root = tk.Tk()
root.geometry('400x100')
fig2, avail = plt.subplots(figsize=(10,7), dpi=60, facecolor= '#e9eef0',)
avail.tick_params(axis='y', labelsize=0)#FORMatar a fonte yLabel
avail.set_ylabel('FOLLOWING THE PRODUCTION', fontsize=20)
avail.set_xlabel('TIME (minute)', fontsize=20)
avail.legend(['ON','PLANNED','STOP'])
stop = [30]
on = [40]
planned = [70]
x = 1
w = 0.2
avail.barh(x + w, on ,w, color='#22e3e3', edgecolor = 'black', linewidth = 2)
avail.barh(x, planned , w ,color='#05337d', edgecolor = 'black', linewidth = 2)
avail.barh(x - w, stop, w, color = '#c95924', edgecolor = 'black', linewidth = 2)
#criando figura para plotar dentro do TKinter
canvas_avail = FigureCanvasTkAgg(fig2, master=root)
canvas_avail.get_tk_widget().place(x= 280, y= 150)
root.mainloop()
进行一些更改并指出错误后,这是另一个代码,这次它可以工作并显示图例:
import tkinter as tk
import matplotlib.pyplot as plt
from matplotlib.figure import Figure
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
root = tk.Tk()
root.geometry('600x450')
fig2, avail = plt.subplots(figsize=(10,7), dpi=60, facecolor='#e9eef0',)
avail.tick_params(axis='y', labelsize=0)
avail.set_ylabel('FOLLOWING THE PRODUCTION', fontsize=20)
avail.set_xlabel('TIME (minute)', fontsize=20)
stop = [30]
on = [40]
planned = [70]
x = 1
w = 0.2
avail.barh(x + w, on, w, color='#22e3e3', edgecolor='black', linewidth=2)
avail.barh(x, planned, w, color='#05337d', edgecolor='black', linewidth=2)
avail.barh(x - w, stop, w, color='#c95924', edgecolor='black', linewidth=2)
# Legend added after creating bars
avail.legend(['ON', 'PLANNED', 'STOP'])
#criando figura para plotar dentro do TKinter
canvas_avail = FigureCanvasTkAgg(fig2, master=root)
canvas_avail.get_tk_widget().place(x=10, y=0)
root.mainloop()
证明:
以上就是如何将图例Matplotlib TKinter的详细内容,更多请关注编程网其它相关文章!
--结束END--
本文标题: 如何将图例Matplotlib TKinter
本文链接: https://lsjlt.com/news/567208.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0