Set left margin?

67 views
Skip to first unread message

Israel Brewster

unread,
Jul 1, 2019, 3:12:02 PM7/1/19
to pyqtgraph
How can I set the left margin of the graph such that the y-axis labels don't get cut off? I generated my plot by calling pg.PlotWidget(), and when I generate my graph and save it to disk (using .grab() on the plot widget), the y-axis labels are all cut off. I have tried setContentsMargins() on the PlotWidget, setting tickTextWidth on the y-axis (obtained via plot.getPlotItem().getAxis('left') ), and adding the plot widget to a layout in another widget and calling setContentsMargins on those, and none of those seems to have any effect on how much space is available for the labels. How can I fix this? Thanks.

Jeremy Webster

unread,
Jul 11, 2019, 6:39:49 PM7/11/19
to pyqtgraph

Try

plot.getPlotItem().getAxis('left').setWidth(80)

The 80 is the number of pixels wide you want the axis labels to have. I tend to find a value that works and hard code that, but you could calculate the width of the tick strings and set it to the widest string if you wanted.



Reply all
Reply to author
Forward
0 new messages