How to remove left and right curve padding in the viewbox

22 views
Skip to first unread message

JJ

unread,
May 29, 2019, 3:01:39 AM5/29/19
to pyqtgraph
When data is plotted there is a padding between the first and last x points by default.
For example, when I plot using the following, the first x axis value is approximately 1e-3 rather than 0.
How can I plot the data so that xmin and xmax on the x axis correspond to xmin and xmax of the plotted data? Do I have to manually set the x limits or is there a setting for this?


from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import pyqtgraph as pg
import numpy as np
import sys


class PlotWidget(pg.GraphicsLayoutWidget):
    
    def __init__(self):
        super().__init__()
        self.myplot = self.addPlot()
        self.viewbox = self.myplot.getViewBox() #correct method
        self.myplot.showGrid(True,True, 1)
        
        x = np.linspace(0,20e-3, 100)
        y = 2*np.sin(2*np.pi*50*x)
        curve = self.myplot.plot(x, y)
        self.show()
        
if __name__ == '__main__':
    app = QApplication(sys.argv)
    plot = PlotWidget()
    sys.exit(app.exec_())


Reply all
Reply to author
Forward
0 new messages