簡體   English   中英

PyQtgraph y 軸標簽非科學記數法

[英]PyQtgraph y axis label non scientific notation

PyQtgraph Y 軸標簽以科學計數法顯示。 我不希望它采用科學記數法。 將標簽更改為非科學的代碼是什么。

在此處輸入圖片說明

科學記數法 - 1.70 (x1e+06)

非科學記數法 1700000(我想以非科學記數法顯示 Y 軸)。

在 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 不包含 set_scientific(False)。 最好的解決方案是覆蓋 AxisItem.tickStrings 將有助於創建自定義標簽。

在此處輸入圖片說明

下面是代碼。

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