Matplotlib imshow和kivy [英] Matplotlib imshow and kivy
问题描述
我有一个3D numpy数组,表示3D断层图像I = [i,j,k].
I have a 3D numpy array, representing a 3D tomographic image I = [i,j,k].
我开始学习kivy,因为我需要做一个简单的GUI,该GUI包括一个用于3D(s = [i,:,:])图像的每个切片的2D图像查看器和一个在平面上移动的切片器.
I started to learn kivy as I need to do a simple GUI consisting of a 2D image viewer for each slice of the 3D (s = [i,:,:]) image and a slicer to move across planes.
我通常通过matplotlib进行所有可视化,我坚信最简单的方法是将matplotlib连接到kivy.我该怎么做? 我看到另一个问题,它提出了一个类似的问题,但仅具有plot函数,该方法似乎不适用于imshow. (如何开始/使用matplotlib在猕猴桃中).
I usually perform all visualization via matplotlib and I tough that the easiest way will be to connect matplotlib to the kivy. How can I do it? I saw another question which ask a similar question, but only with the plot function, and the methodology does not seems to work for imshow. (How to get started/use matplotlib in kivy).
有什么建议吗?
谢谢
推荐答案
有关详细信息,请参阅示例.
Please refer to the example for details.
from kivy.garden.matplotlib.backend_kivyagg import FigureCanvasKivyAgg
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
img = mpimg.imread('ac013.JPG')
lum_img = img[:, :, 0]
plt.imshow(lum_img, cmap="nipy_spectral")
plt.colorbar()
class TestApp(App):
title = "Kivy Garden Matplolib & imshow()"
def build(self):
box = BoxLayout()
box.add_widget(FigureCanvasKivyAgg(plt.gcf()))
return box
if __name__ == "__main__":
TestApp().run()
输出
这篇关于Matplotlib imshow和kivy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!