我正在尝试创建一个简单的 DICOM 查看器,在其中我使用 matplotlib 绘制图像,并且我想在 tkinter 中显示相同的图(这是一个 DICOM 图像),但是当我运行代码时出现此错误。请帮忙。当我尝试绘制 a 时会发生错误,但我相信它与我声明 x、y 和 p 的值的方式有关
import pydicom
import matplotlib
matplotlib.use('TkAgg')
import numpy as np
from matplotlib.backends.backend_tkagg import
FigureCanvasTkAgg
from matplotlib.figure import Figure
from tkinter import *
from pydicom.data import get_testdata_files
filename = get_testdata_files('000000.dcm')
dataset = pydicom.dcmread('000000.dcm')
data = dataset.pixel_array
class mclass:
def __init__(self, window):
self.window = window
self.button=Button(window,text="check",command=self.plot)
self.button.pack()
def plot (self):
if 'PixelData' in dataset:
rows = int(dataset.Rows)
cols = int(dataset.Columns)
y=np.array(rows)
x=np.array(cols)
p=np.array(data)
fig = Figure(figsize=(6,6))
a = fig.add_subplot(111)
a.plot(p, range(2+max(y)))
canvas = FigureCanvasTkAgg(fig, master=self.window)
canvas.get_tk_widget().pack()
canvas.draw()
window = Tk()
start = mclass (window)
window.mainloop()