Matplotlib imshow and kivy(Matplotlib imshow 和 kivy)
问题描述
我有一个 3D numpy 数组,代表一个 3D 断层图像 I = [i,j,k].
我开始学习 kivy,因为我需要做一个简单的 GUI,该 GUI 由一个 2D 图像查看器组成,用于 3D (s = [i,:,:]) 图像的每个切片和一个用于跨平面移动的切片器.
我通常通过 matplotlib 执行所有可视化,我认为最简单的方法是将 matplotlib 连接到 kivy.我该怎么做?我看到另一个问题,它提出了类似的问题,但仅限于绘图功能,并且该方法似乎不适用于 imshow.(
I have a 3D numpy array, representing a 3D tomographic image I = [i,j,k].
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.
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).
Any suggestions?
Thanks,
Please refer to the example for details.
Example
main.py
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()
Output
这篇关于Matplotlib imshow 和 kivy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Matplotlib imshow 和 kivy
基础教程推荐
- 用于分类数据的跳跃记号标签 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 筛选NumPy数组 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01