首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >PyQtgraph y轴标签非科学记数法

PyQtgraph y轴标签非科学记数法
EN

Stack Overflow用户
提问于 2017-05-04 16:52:42
回答 1查看 5.1K关注 0票数 2

PyQtgraph Y轴标签以科学记数法显示。我不希望它使用科学记数法。将标签更改为非科学标签的代码是什么?

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

非科学记数法1700000 (我想以非科学记数法显示Y轴)。

在main()函数中,我调用addXYZ来添加等高线,然后调用Show2dPlot来显示等值线图。

代码语言:javascript
运行
复制
##### 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
EN

回答 1

Stack Overflow用户

发布于 2017-05-04 19:50:47

PyQtgraph不包含set_scientific(False)。最好的解决方案是覆盖AxisItem.tickStrings将有助于创建自定义标签。

下面是代码。

代码语言:javascript
运行
复制
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()
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43778148

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档