Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Description
Bug summary
I ran into this bizarre bug, I am not sure if it's a skill issue on my end, but I am trying to embed a plot in my qt6 application. Allowing the user to plot and replot for some reason keeps increasing the sizes of my chart elements, butonly when I have display scaling on (e.g. 125%, 150% etc). To illustrate:
See below for the code, basically I am creating a new plot every time there is a mouse click on that row. Embeddingprint(self.chart.figure.dpi)
shows that my plot's dpi keeps doubling every other time I trigger a click. Console output:
100.0100.0200.0200.0400.0400.0
I can workaround this by explicitly setting the figure DPI, e.g. figure.dpi = 100 when creating it. But I assume that means I'm giving up display scaling
Code for reproduction
importmatplotlibmatplotlib.use("Qt5Agg")frommatplotlib.backends.backend_qt5aggimportFigureCanvasQTAggfrommatplotlib.figureimportFigurefromPyQt6.QtWidgetsimport (QWidget,QVBoxLayout,QFrame)classGraphView(QWidget):def__init__(self):super().__init__()self.layout=QVBoxLayout()self.separator=Noneself.chart=MplCanvas()self.figures=Noneself.init_widget()definit_widget(self):self.init_separator()self.layout.addWidget(self.separator)self.layout.addWidget(self.chart)self.setLayout(self.layout) ...# Note this is the code that triggers when I click a row.defupdate_graph(self,figure):self.chart.deleteLater()self.chart=MplCanvas(fig=figure)self.layout.addWidget(self.chart)self.layout.update()classMplCanvas(FigureCanvasQTAgg):def__init__(self,fig=Figure()):super(MplCanvas,self).__init__(fig)
Actual outcome
Figure DPI keeps dynamically doubling
Expected outcome
DPI shouldn't double like that, it's madness
Additional information
No response
Operating system
Windows, Linux
Matplotlib Version
3.6.3
Matplotlib Backend
QtAgg
Python version
3.11.4
Jupyter version
No response
Installation
pip