Mac OS Python 3.8.5
PyQt5 5.15.2 PyQt5-sip 12.8.1 pyqtgraph 0.11.1
pip install PyQt5 PyQt5-sip pyqtgraph
I'm using numpy for plotting. pip install numpy
"""Set the size ratio of the graph"""
import dataclasses
import itertools
from typing import Optional
import sys
import numpy as np
from PyQt5 import QtWidgets #Almost never used
import pyqtgraph as pg
SAMPLE_DATA1 = np.linspace(-100, 100) ** 1
SAMPLE_DATA2 = np.linspace(-100, 100) ** 2
SAMPLE_DATA3 = np.linspace(-100, 100) ** 3
@dataclasses.dataclass
class ChangeSizeRatioWidget(pg.GraphicsLayoutWidget):
"""Main screen
Attributes #
----------
parent: Optional[QtWidgets.QWidget] default=None
Parent screen
"""
parent: Optional[QtWidgets.QWidget] = None
def __post_init__(self) -> None:
"""Load superclass and add plot"""
super(ChangeSizeRatioWidget, self).__init__(parent=self.parent)
self.plotter1 = self.addPlot(row=0, col=0)
self.plotter1.showGrid(x=True, y=True, alpha=0.8)
self.plotter1_curve = self.plotter1.plot(pen=pg.mkPen('#f00', width=5))
self.plotter1_curve.setData(SAMPLE_DATA1)
self.plotter2 = self.addPlot(row=0, col=1)
self.plotter2.showGrid(x=True, y=True, alpha=0.8)
self.plotter2_curve = self.plotter2.plot(pen=pg.mkPen('#00f', width=5))
self.plotter2_curve.setData(SAMPLE_DATA2)
self.ci.layout.setColumnStretchFactor(0, 8)
self.ci.layout.setColumnStretchFactor(1, 5)
def main():
app = QtWidgets.QApplication(sys.argv)
window = ChangeSizeRatioWidget(parent=None)
window.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main()
self.ci.layout.setColumnStretchFactor(0, 8)
self.ci.layout.setColumnStretchFactor(1, 5)
pg.GraphicsLayoutWidget.ci.layout.setColumnStretchFactor(col, size) col-> column index size-> ratio
When changing for a line
self.ci.layout.setRowStretchFactor(0, 8)
self.ci.layout.setRowStretchFactor(1, 5)
is
Straddle multiple columns
"""Straddle multiple columns"""
import dataclasses
import itertools
from typing import Optional
import sys
import numpy as np
from PyQt5 import QtWidgets #Almost never used
import pyqtgraph as pg
SAMPLE_DATA1 = np.linspace(-100, 100) ** 1
SAMPLE_DATA2 = np.linspace(-100, 100) ** 2
SAMPLE_DATA3 = np.linspace(-100, 100) ** 3
@dataclasses.dataclass
class ChangeSizeRatioWidget(pg.GraphicsLayoutWidget):
"""Main screen
Attributes #
----------
parent: Optional[QtWidgets.QWidget] default=None
Parent screen
"""
parent: Optional[QtWidgets.QWidget] = None
def __post_init__(self) -> None:
"""Load superclass and add plot"""
super(ChangeSizeRatioWidget, self).__init__(parent=self.parent)
self.plotter1 = self.addPlot(row=0, col=0)
self.plotter1.showGrid(x=True, y=True, alpha=0.8)
self.plotter1_curve = self.plotter1.plot(pen=pg.mkPen('#f00', width=5))
self.plotter1_curve.setData(SAMPLE_DATA1)
self.plotter2 = self.addPlot(row=0, col=1)
self.plotter2.showGrid(x=True, y=True, alpha=0.8)
self.plotter2_curve = self.plotter2.plot(pen=pg.mkPen('#00f', width=5))
self.plotter2_curve.setData(SAMPLE_DATA2)
self.plotter3 = self.addPlot(row=1, col=0, colspan=2)
self.plotter3.showGrid(x=True, y=True, alpha=0.8)
self.plotter3_curve = self.plotter3.plot(pen=pg.mkPen('#0f0', width=5))
self.plotter3_curve.setData(SAMPLE_DATA3)
def main():
app = QtWidgets.QApplication(sys.argv)
window = ChangeSizeRatioWidget(parent=None)
window.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main()
self.plotter3 = self.addPlot(row=1, col=0, colspan=2)
Set with colspan
I forgot,,
Recommended Posts