【发布时间】:2020-08-01 06:29:00
【问题描述】:
在 kivy 中,我打开了一个模态视图,在该模态视图中是一个 Boxlayout,它将有 2 个小部件。 1 个小部件可以是任何东西,另一个是 matplotlib 图 - 所以我可以同时看到两者。
我无法让 modalview 与 matplotlib 一起工作,当我运行它时,它会取消 modalview 并只显示 matplotlib - 再一次,整个 modalview 只是没有出现,它只是情节。我尝试用有限的 size_hint 制作另一个 kivy 小部件,然后将绘图添加到其中,然后将小部件添加到我的主 boxlayout 但结果相同
我已经附上了我的 kivy 代码和情节代码,图像是我希望模态视图看起来的样子,右侧是情节
最后,我确信还有其他方法可以做我想做的事,比如 matplotlib 有我可以使用的小部件。但这似乎是一种不好的做法,突然从我一直使用的 kivy 转变为我打赌可以以某种方式做到这一点
有什么建议吗?
mainview = ModalView(size_hint = (0.6, 0.7))
box = BoxLayout(orientation = 'horizontal') # cols not rows
box.add_widget(Button(text = "place holder", size_hint_x = 0.3))
box.add_widget(python_testing.make_plot())
mainview.add_widget(box)
mainview.open()
# this is python_testing.make_plot() mentioned above
# Prepare the data
x = [1,2,3,4,5,6,7,8,9,10]
ratings = [4,5,8,9,4,3,2,6,8,7]
plt.figure(num='cde')
plt.plot(x, ratings, label='cde')
plt.legend() # Add a legend
plt.show() # Show the plot
【问题讨论】:
-
我找到了不同的解决方案。我没有找到使用 matplotlib 的解决方案。查看答案
标签: python matplotlib user-interface kivy