pyqtgraph ticks auf der x Achse wiederhohlen

35 views
Skip to first unread message

Herbert Abisul

unread,
Nov 20, 2023, 2:47:56 AM11/20/23
to pyqtgraph
Hello everyone, Does anyone have an idea how I could use pyqtgraph (PyQt5) to repeat the x-axis when creating a graph? So the x-axis goes from 0-3 and then again from 0-3 with different y-values ​​(see example x and associated y array)? Here is a minimal example:

[code]
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtSerialPort import *
from PyQt5.QtCore import *
import pyqtgraph as pg

class MyWindow(QMainWindow):
def __init__(self):
super().__init__()

MPU_mag = [1,2,3,1,2,3]
MPU_freq = [5, 6, 5, 3, 4, 3]

self.setGeometry(100, 100, 1500, 900)
self.setWindowTitle("BarGraph example")

hlay = QGridLayout(self)
self.graphWidget55 = pg.PlotWidget()

widget = QWidget()
widget.setLayout(hlay)
self.setCentralWidget(widget)
new_ticks = [f'{value:.2f}' for value in MPU_mag]
self.graphWidget55.getAxis("bottom").setTicks([list(zip(MPU_mag, new_ticks))])
self.bar_graph_item = pg.BarGraphItem(x=MPU_mag, height=MPU_freq, width=0.01, brush=QBrush(Qt.red))
self.graphWidget55.addItem(self.bar_graph_item)

hlay.addWidget(self.graphWidget55, 0, 0)


if __name__ == "__main__":
app = QApplication(sys.argv)
window = MyWindow()
window.show()
sys.exit(app.exec_())
[code]

thanks and nice day
Reply all
Reply to author
Forward
0 new messages