修改图形格

问题描述 投票:0回答:1

如何修改我的图形的网格味道?为了使画面变大或变小。

我想修改刻度和字幕。

目前我的图形是这样的。

但是,我需要的是这样的。

这是我的程序的所有代码。

# -*- 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个回答
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()

结果:result

编辑:

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
© www.soinside.com 2019 - 2024. All rights reserved.