4

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?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Kroll
  • 649
  • 2
  • 6
  • 17

1 Answers1

6

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')})
misantroop
  • 2,276
  • 1
  • 16
  • 24
  • Is this still the way to go? Does work, just wondering if there is a better way/simpler. Tx – Je Je Mar 04 '22 at 22:18