Kro*_*oll 4 python pyqt pyqtgraph
我在 Y 轴上看到这样的数字:
1.935
1.9325
1.93
1.9275
1.925
Run Code Online (Sandbox Code Playgroud)
但我需要看到这个:
1.9350
1.9325
1.9300
1.9275
1.9250
Run Code Online (Sandbox Code Playgroud)
如何设置 AxisItem 以始终显示小数点后固定的位数?
您需要对 AxisItem 进行子类化并使用 tickStrings 来格式化值:
class FmtAxisItem(pg.AxisItem):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def tickStrings(self, values, scale, spacing):
return [f'{v:.4f}' for v in values]
Run Code Online (Sandbox Code Playgroud)
然后告诉绘图仪使用轴:
self.chartWidget = pg.PlotWidget(axisItems={'left': FmtAxisItem(orientation='left')})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
884 次 |
| 最近记录: |