【问题标题】:Modify graphic grid修改图形网格
【发布时间】:2019-06-19 10:56:50
【问题描述】:

如何修改图形的网格以符合口味?使图片变大或变小。

我想修改勾选和字幕。

目前我的图形是这样的。

但我需要它是这样的。

这是我程序的全部代码。

# -*- coding: utf-8 -*-

try:
    from PySide import QtWidgets
except:
    from PyQt5 import QtWidgets


class ECG1:
    def __init__(self):

......................

【问题讨论】:

    标签: python python-3.x pyqt pyqt4 pyqtgraph


    【解决方案1】:

    我猜到了你的刻度间距,你可能需要调整它们:

    import pyqtgraph as pg
    import numpy as np
    
    if __name__ == '__main__':
    
        app = pg.mkQApp()
        pg.setConfigOption('background', 'w')
        pg.setConfigOption('foreground', 'k')
        pw = pg.PlotWidget()
        plotItem = pw.getPlotItem()
    
        axBottom = plotItem.getAxis('bottom') #get x axis
        xTicks = [0.2, 0.04]
        axBottom.setTickSpacing(xTicks[0], xTicks[1]) #set x ticks (major and minor)
        axLeft = plotItem.getAxis('left') #get y axis
        yTicks = [20000, 4000]
        axLeft.setTickSpacing(yTicks[0], yTicks[1]) #set y ticks (major and minor)
        plotItem.showGrid(x=True, y=True, alpha=0.3)
        plotItem.vb.state['aspectLocked'] = yTicks[0]/xTicks[0] # lock aspect ratio (major ticks form a square)
    
        # plot an unhealthy cardiogram
        x = np.linspace(0,5,1000)
        pw.plot(x,np.sin(x*10)*30000, pen='k')
        pw.show()
        app.exec()
    

    结果:

    编辑:

    class ExampleApp(QtGui.QMainWindow, ui_main.Ui_MainWindow):
        def __init__(self, parent=None):
            pyqtgraph.setConfigOption('background', 'w') #before loading widget, fondo de la gráfica.
    
            super(ExampleApp, self).__init__(parent)
            self.setupUi(self)
        #### Insert the code here
            plotItem = self.grECG.plotItem
            axBottom = plotItem.getAxis('bottom') #get x axis
            xTicks = [0.2, 0.04]
            axBottom.setTickSpacing(xTicks[0], xTicks[1]) #set x ticks (major and minor)
            axLeft = plotItem.getAxis('left') #get y axis
            yTicks = [20000, 4000]
            axLeft.setTickSpacing(yTicks[0], yTicks[1]) #set y ticks (major and minor)
            plotItem.showGrid(x=True, y=True, alpha=0.3)
            plotItem.vb.state['aspectLocked'] = yTicks[0]/xTicks[0] # lock aspect ratio (major ticks form a square)
        #### Continue with your code
            #self.grECG.plotItem.setStyle(tickLength=1) #línea de walter
            #self.grECG.plotItem.setScale(2.0) #cambia la escala de la ventana de muestreo.
            #etc
    

    【讨论】:

    • 您好,非常感谢您的回复,这正是我应该做的,但请原谅我的问题,我该如何在我的代码中实现它?我真的很新,我试过了,但它给了我一个错误。 " 文件 "go.py",第 30 行 xTicks = [0.2, 0.04] ^ IndentationError: unexpected indent"
    • 乔纳斯,请帮忙:(
    • @Antoniovg 我添加了将代码插入我的答案的位置。 (假设self.grECG.plotItem 是PlotItem)
    • 您好,非常感谢您的回复,我在您指出我的地方添加了代码。但我收到此错误:文件“go.py”,第 28 行 plotItem = self.grECG.plotItem ^ IndentationError: unexpected indent
    • 就像错误所说的那样,你有一个缩进,不应该有一个。您没有发布所有代码,但您可能必须在所有以class ExampleApp... 开头的行之前删除缩进。 indentation
    猜你喜欢
    • 2021-12-08
    • 2022-01-24
    • 2015-06-16
    • 1970-01-01
    • 2012-01-03
    • 1970-01-01
    • 1970-01-01
    • 2019-09-18
    • 1970-01-01
    相关资源
    最近更新 更多