2017-11-27 31 views
0

matplotlibで画像を開き、matplotlibプロットに埋め込み、Tkinterウィジェットに表示したいとします。私はTkinterにmatplotlibグラフを表示する方法を知っていますが、画像でそれを行う方法はわかりません。ここに私のコード:matplotlibに画像を埋め込んでTkinterに表示

import matplotlib.pyplot as plt 
import matplotlib.image as mpimg 
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg 
from matplotlib.figure import Figure 
from numpy import array, arange, sin, pi 

root = Tk() 
root_panel = Frame(root) 
root_panel.pack(side="bottom", fill="both", expand="yes") 

btn_panel = Frame(root_panel, height=35) 
btn_panel.pack(side='top', fill="both", expand="yes") 

img_arr = mpimg.imread('img/pic.jpg') 
imgplot = plt.imshow(img_arr) 

#here is the example of how I embed matplotlib graph in Tkinter, 
#basically, I want to do the same with the image (imgplot) 
f = Figure() 
a = f.add_subplot(111) 
t = arange(0.0, 3.0, 0.01) 
s = sin(2*pi*t) 
a.plot(t, s) 

canvas = FigureCanvasTkAgg(f, master=root) 
canvas.show() 
canvas.get_tk_widget().pack(side="top", fill="both", expand=1) 
canvas._tkcanvas.pack(side="top", fill="both", expand=1) 

root.mainloop() 
+1

'a.plot(t、s)'を 'a.imshow(img_arr) 'に置き換えることは何をしますか? –

+0

はい、私の愚かさのために申し訳ありません:D –

答えて

0

Tkinterのウィンドウ内に埋め込まmatplotlibの図に画像を表示するには、行うことがあり、すべての質問に与えられたコードでa.imshow(img_arr)a.plot(t, s)を交換です。

関連する問題