简体   繁体   English

PyQtgraph y 轴标签非科学记数法

[英]PyQtgraph y axis label non scientific notation

PyQtgraph Y axis label is displaying in scientific notation. PyQtgraph Y 轴标签以科学计数法显示。 I do not want it to be in scientific notation.我不希望它采用科学记数法。 What is the code to change label to non scientific.将标签更改为非科学的代码是什么。

在此处输入图片说明

Scientific notation - 1.70 (x1e+06)科学记数法 - 1.70 (x1e+06)

non Scientific notation 1700000 (I want to display Y axis in non scientific notation).非科学记数法 1700000(我想以非科学记数法显示 Y 轴)。

from main() function I call addXYZ to add contour lines, then I call Show2dPlot to display the contour map plot.在 main() 函数中,我调用 addXYZ 添加等高线,然后调用 Show2dPlot 显示等高线图。

##### add the XY contour line to plot #####       
    def addXYZ(self, X, Y, Z):
        self.plotwin.plot(X, Y, pen=(255,255,255))#cmap=cm.coolwarm)


##### Format 2D Plot #####        
    def Show2dPlot(self):
        self.plotwin.setLogMode(x=False, y=False)
        self.plotwin.showGrid(x=True, y=True)
        self.plotwin.setLabel('left', "Easting")# units='A')
        self.plotwin.setLabel('bottom', "Northing") #, units='s')
        self.plotwin.setAspectLocked()
        self.plotwin.set_scientific(False) #I'm getting error in set_scientific

PyQtgraph does not contain set_scientific(False). PyQtgraph 不包含 set_scientific(False)。 The best solution is to override the AxisItem.tickStrings will help to create custom labels.最好的解决方案是覆盖 AxisItem.tickStrings 将有助于创建自定义标签。

在此处输入图片说明

Below is the code.下面是代码。

import sys
from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg

##### Override class #####
class NonScientific(pg.AxisItem):
    def __init__(self, *args, **kwargs):
        super(NonScientific, self).__init__(*args, **kwargs)

    def tickStrings(self, values, scale, spacing):
        return [int(value*1) for value in values] #This line return the NonScientific notation value

class MyApplication(QtGui.QApplication):
    def __init__(self, *args, **kwargs):

        self.win = pg.GraphicsWindow(title="Contour plotting")
        self.win.resize(1000,600)

        self.plot = self.win.addPlot(title='Contour', axisItems={'left': NonScientific(orientation='left')})
        self.curve = self.plot.plot()


    def PlotContour(self):
        x = range(50000,60000,10000)#X coordinates of contour
        y = range(500000,600000,100000)#Y coordinates of contour
        self.curve.setData(x=x, y=y)
        self.curve.autoRange()

def main():
    app = MyApplication(sys.argv)
    sys.exit(app.exec_())

if __name__ == '__main__':
    main()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM