我只想在数据点的位置显示xticks (所以xticks是==波长)。我该怎么做?
这是我的代码:
from PyQt6.QtWidgets import QApplication
import pyqtgraph as pg
app = QApplication([])
wavelengths = [610, 680, 730, 760, 810, 860]
data = [239.23, 233.81, 187.27, 176.41, 172.35, 173.78]
pw = pg.plot(wavelengths, data, symbol="o")
pw.getPlotItem().getAxis('bottom').setTicks([wavelengths])
app.exec()
我尝试使用AxisItem.setTicks(),但是它导致了一个错误:
for val, strn in level:
TypeError: cannot unpack non-iterable int object
Traceback (most recent call last):
File "/home/jure/.local/share/virtualenvs/serial-plotting-gui-dWOiQ7Th/lib/python3.10/site-packages/pyqtgraph/graphicsItems/AxisItem.py", line 608, in paint
specs = self.generateDrawSpecs(painter)
File "/home/jure/.local/share/virtualenvs/serial-plotting-gui-dWOiQ7Th/lib/python3.10/site-packages/pyqtgraph/graphicsItems/AxisItem.py", line 936, in generateDrawSpecs
我也试过this SO answer,但对我不起作用
发布于 2022-02-11 18:28:56
它总是有点棘手的蜱在比例尺。它与轴上两个滴答之间的滴答间距一起工作。在此基础上,定义了MajorTick、MinorTicks等级别。对于setTicks
,您必须指定级别列表(我们只有MajorTicks),而每个级别都必须指定(tick value, "tick string")
列表。
因此,为了使示例工作,您必须使用这样的列表作为setTicks
方法的参数。
以下是您修改的代码:
from PyQt6.QtWidgets import QApplication
import pyqtgraph as pg
app = QApplication([])
wavelengths = [610, 680, 730, 760, 810, 860]
data = [239.23, 233.81, 187.27, 176.41, 172.35, 173.78]
pw = pg.plot(wavelengths, data, symbol="o")
pw.getPlotItem().getAxis('bottom').setTicks([[(wavelength, str(wavelength)) for wavelength in wavelengths]])
app.exec()
https://stackoverflow.com/questions/71081359
复制相似问题