修改图形网格

时间:2019-01-25 15:18:10

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

如何修改图形的网格以使其具有品味?要放大或缩小图片。

我要修改刻度线和字幕。

目前我的图形是这样的。

enter image description here

但是我需要这样。

enter image description here

这是我程序的所有代码。

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

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


class ECG1:
    def __init__(self):

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

1 个答案:

答案 0 :(得分: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