【问题标题】:PyQtgraph y axis label non scientific notationPyQtgraph y轴标签非科学记数法
【发布时间】:2017-10-02 08:29:23
【问题描述】:

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

【问题讨论】:

  • 使用set_scientific(False)
  • @RaminNietzsche 我收到 NameError,PyQtgraph 可能没有 set_scientific。 :(
  • 你能分享你的部分代码吗?

标签: python pyqt4 pyqtgraph


【解决方案1】:

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()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-26
    • 2021-06-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多