我不明白将matplotlib图形链接到从Qt Designer创建的表单的最佳方法.我有一个我在QtDesigner中创建的表单,然后通过pyuic5编译为python.我的主要计划是:
import app_framework as af
import matplotlib
from PyQt5 import QtWidgets
import sys
matplotlib.use('Qt5Agg')
app = QtWidgets.QApplication(sys.argv)
form = af.MyApp()
form.show()
app.exec_()
Run Code Online (Sandbox Code Playgroud)
其中myApp调用从Qt Designer创建的app_framework.py表单,然后由pyuic5(design.py)转换:
from PyQt5.QtWidgets import QApplication, QMainWindow
import design
class MyApp(QMainWindow, design.Ui_mainWindow):
def __init(self):
super(self.__class__, self).__init__()
<button initializations>
<function definitions for button callbacks>
Run Code Online (Sandbox Code Playgroud)
我很困惑在这个框架中我可以将matplotlib图形链接到QtDesigner中的预制空窗口小部件,或类似的东西,这样我就可以在GUI窗口中绘制新数据(事情发生,按钮按下)等)
我在SO和matplotlib的网站上找到了一些线程,但我不确定我是否理解在Qt Designer表单中为这个小部件创建空间的正确过程,然后链接一个绘图,和/或创建一个小部件post hoc和然后链接和绘图.
到目前为止我所做的是在Qt Creator中创建一个空的QWidget,然后在pyuic5编译之后,我改变了design.py文件,如下所示:
from PyQt5 import QtCore, QtGui, QtWidgets
# **** ADDED THIS
from matplotlib.figure import Figure
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as Canvas
# ****
class Ui_mainWindow(object): …Run Code Online (Sandbox Code Playgroud) 当我运行此示例并创建矩形选区时,如果我缩放或移动选区周围的绘图窗口消失,直到我取消选择移动或缩放工具并再次单击绘图窗口.
我%matplotlib tkinter在IPython笔记本中使用.
我试图挂钩窗口缩放时发生的极限变化并将矩形选择设置为可见:
def persist_rect(newlims):
rs = toggle_selector.RS
print(rs.visible)
rs.set_visible(True)
rs.update()
current_ax.callbacks.connect('xlim_changed', persist_rect)
current_ax.callbacks.connect('ylim_changed', persist_rect)
Run Code Online (Sandbox Code Playgroud)
但这似乎没有做任何事情.它甚至没有toggle_selector.RS.visible被设置为假.
我也一直在寻找RectangleSelector的源代码,但我还没有看到任何有启发性的东西.
我还发现,当我使用修改所选区域的范围时,我遇到了这个问题RectangleSelector.extents = new_extents.当.extents被修改,例如采用了滑盖的小部件,选定区域中消失,直到我再次对剧情点击.
如果RectangleSelector用useblit=False@ImportanceOfBeingErnest建议初始化所有这些问题就会消失,但正如他们所说,这不是一个非常高效的解决方案.
我已经尝试了几个小时来获得正确的简单单选按钮列表的大小和纵横比,但没有成功。首先,导入模块:
import matplotlib.pyplot as plt
from matplotlib.widgets import RadioButtons
Run Code Online (Sandbox Code Playgroud)
然后创建实际的单选按钮:
plt.figure()
rax = plt.axes([0.1, 0.1, 0.6, 0.6], frameon=True)
labels = [str(i) for i in range(10)]
radio = RadioButtons(rax, labels)
Run Code Online (Sandbox Code Playgroud)
如果我使用 plt.axes 的 'aspect' 参数并将其设置为 'equal':
plt.figure()
rax = plt.axes([0.1, 0.1, 0.6, 0.6], frameon=True, aspect='equal')
labels = [str(i) for i in range(10)]
radio = RadioButtons(rax, labels)
Run Code Online (Sandbox Code Playgroud)
如果我仍然使用设置为“相等”的“方面”参数将高度降低到 0.3,我只会得到先前结果的较小版本(较小的按钮但仍然在较小的轴实例中重叠)。
我真正想做的是具有非常窄的宽度和较大的高度,并且仍然具有不重叠的圆形单选按钮:
plt.figure()
rax = plt.axes([0.1, 0.1, 0.2, 0.8], frameon=True)
labels = [str(i) for i in range(10)]
radio = RadioButtons(rax, labels)
Run Code Online (Sandbox Code Playgroud)
但这会生成垂直椭圆形的单选按钮: …
我正在构建一个带有基于Jupyter和Voila 的交互式绘图的 webapp 。里面的笔记本我用ipywidgets处理的交互性和%matplotlib widget后端,所以我可以更新我的阴谋没有重绘全数字(在不工作%matplotlib inline,并%matplotlib notebook在瞧不渲染)。
我的问题是我无法设置图形大小,使其与其画布或容器的大小相匹配,这些画布或容器会在窗口调整大小时自动调整大小。
这是我的情况的一个小工作示例:
%matplotlib widget
from IPython.display import display
import matplotlib.pyplot as plt
import ipywidgets as widgets
import numpy as np
# Output widget that will contain the figure
out = widgets.Output(layout = {
'border': '1px solid black',
# 'width': '100%' # Not needed and does not help
})
# Initializing the figure within out
with out:
fig, ax = plt.subplots(1, constrained_layout=True) …Run Code Online (Sandbox Code Playgroud) 我正在构建一个应用程序,它接受输入,将其保存到 CSV 文件,现在最后一个基本部分是显示列内容的饼图。输入应该是关于书籍的。因此,饼图应该显示列表中所有书籍的类型。
我在创建饼图时没有问题,我在单独的脚本中管理它,我也没有收到错误消息,但只有一个白色字段。
import csv
import tkinter as tk
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
from tkinter import ttk
from collections import Counter
class FrontFrames:
def __init__(self, master):
super().__init__()
#Split the screen horizontally in two parts
top_frame = tk.Frame(master, bg="green")
bottom_frame = tk.Frame(master, bg="yellow")
top_frame.pack(side="top", fill="both", expand=True)
bottom_frame.pack(side="top", fill="both", expand=True)
#Creating the three top widgets
self.tree = Label(top_frame)
column = ("Title", "author", "year", "others")
self.treeview = ttk.Treeview(top_frame, columns=column, show='headings')
self.treeview.heading("Title", text="Title") …Run Code Online (Sandbox Code Playgroud) 我正在开发一个类似 GUI 的示波器项目。虽然 GUI 还没有准备好,但是我遇到了一个问题,当我关闭 TKinter 窗口时,程序没有关闭。它仍然在 python shell 中运行。我想这可能是关闭 tkinter 相关程序的方法。但我发现只要关闭 tkinter 窗口就会杀死程序。就我而言,即使关闭 tkinter 窗口后,程序仍在 python shell 中运行。我把我的代码放在这里,请看看问题出在哪里?
from tkinter import *
from matplotlib import pyplot as plt
import matplotlib.animation as animation
from matplotlib import style
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import numpy as np
root = Tk()
root.geometry("800x500+100+100")
root.title('root window')
frame = Frame(root, borderwidth=1,bg="#0DBDAB") ## This is the frame in which plot will be shown
frame.place(relx=1.0/3,rely=0.5, anchor="center", relwidth=0.60,relheight=0.8)
xar = [0]
yar = [0]
k=0.2 ### This is just …Run Code Online (Sandbox Code Playgroud) 我正在使用PyQt的包装器(pyqtgraph)来构建GUI应用程序。我希望使用MatplotlibWidget在其中嵌入一个Seaborn图 。但是,我的问题是,诸如Seaborn的包装方法不接受外部图形处理。此外,当我尝试用产生的图形更新基于()的MatplotlibWidget对象时,它不起作用(后面没有图形)。有任何解决方法的建议吗?FacetGrid.figFacetGriddraw
接下来的代码绘制了三个子图。
from ipywidgets import widgets
from IPython.display import display
import matplotlib.pyplot as plt
import numpy as np
%matplotlib notebook
fig, (ax1, ax2,ax3) = plt.subplots(nrows=3, figsize=(10,9))
line1, = ax1.semilogx([],[], label='Multipath')
hline1 = ax1.axhline(y = 0, linewidth=1.2, color='black',ls='--')
text1 = ax1.text(0, 0, "T Threshold",
verticalalignment='top', horizontalalignment='left',
transform=ax1.get_yaxis_transform(),
color='brown', fontsize=10)
#ax1.set_xlabel('Separation Distance, r (m)')
ax1.set_ylabel('Received Power, $P_t$ (dBm)')
ax1.grid(True,which="both",ls=":")
ax1.legend()
line2, = ax2.semilogx([],[], label='Monostatic Link')
hline2 = ax2.axhline(y = 0, linewidth=1.2, color='black',ls='--')
text2 = ax2.text(0, 0, "R Threshold",
verticalalignment='top', horizontalalignment='left',
transform=ax2.get_yaxis_transform(),
color='brown', fontsize=10) …Run Code Online (Sandbox Code Playgroud) I am using the matplotlib.widgets to create radio buttons in my widgets, the buttons coming are stacked vertically, I would like them to be stacked horizontally.
MVCE:
import matplotlib.pyplot as plt
from matplotlib.widgets import RadioButtons
plt.subplots_adjust(left=0.2)
rax = plt.axes([0.5,0.05,0.1,0.1])
radio = RadioButtons(rax ,['1','2','3'], active=0, activecolor='blue' )
plt.show()
Run Code Online (Sandbox Code Playgroud)
As you can see with this example you can get the radio buttons like this
,
I am wondering is there a way to stack these radio buttons horizontally.
matplotlib ×7
python ×5
python-3.x ×2
tkinter ×2
animation ×1
figsize ×1
ipywidgets ×1
pie-chart ×1
pyqt ×1
pyqt5 ×1
pyqtgraph ×1
python-2.7 ×1
seaborn ×1
voila ×1