Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to format Y-axis displayed numbers in pyqtgraph?

I see numbers on Y-axis like this:

1.935
1.9325
1.93
1.9275
1.925

But I need to see this:

1.9350
1.9325
1.9300
1.9275
1.9250

How can I set the AxisItem to show always fixed number of digits after decimal point?

like image 608
Kroll Avatar asked Oct 28 '25 05:10

Kroll


1 Answers

You need to subclass the AxisItem and use tickStrings to format the values:

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]

Then tell the plotter to use the axis:

self.chartWidget = pg.PlotWidget(axisItems={'left': FmtAxisItem(orientation='left')})
like image 146
misantroop Avatar answered Oct 31 '25 11:10

misantroop