问题描述
我正在使用 Latex 和 matplotlib 库来获取画布图像中的输出
但我需要字符串形式的输出。
这是我的 tkinter 代码
import matplotlib
import matplotlib.pyplot as plt
# import numpy as np
# import base64
from matplotlib.backends.backend_tkagg import figureCanvasTkAgg
matplotlib.use('TkAgg')
from tkinter import *
def graph(text):
tmptext = entry.get()
tmptext = "$"+tmptext+"$"
ax.clear()
ax.text(0,0.9,tmptext,fontsize = 16)
canvas.draw()
# s,(width,height) = canvas.print_to_buffer()
# x = np.fromstring(s,np.uint8).reshape((height,width,4))
# y = np.array_str(x)
# print(y)
# imagedata = base64.b64encode()
# print(imagedata)
# canvast = Canvas(root,width=400,height=500)
# canvast.pack()
# canvast.create_text(100,10,text=""")
root = Tk()
mainframe = Frame(root)
mainframe.pack()
text = StringVar()
entry = Entry(mainframe,width=70,textvariable=text)
entry.pack()
label = Label(mainframe)
label.pack()
fig = matplotlib.figure.figure(figsize=(10,4),dpi=100)
ax = fig.add_subplot(111)
canvas = figureCanvasTkAgg(fig,master=label)
canvas.get_tk_widget().pack(side=TOP,fill=BOTH,expand=1)
canvas._tkcanvas.pack(side=TOP,expand=1)
ax.get_xaxis().set_visible(False)
ax.get_yaxis().set_visible(False)
root.bind('<Return>',graph)
root.mainloop()
这是我的输出
以上输出是画布图像,我想将其转换为字符串格式
有什么方法可以将画布图像转换为字符串格式
请帮我解决这个问题
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)