I am trying to build simple user interface with a graph. The combination of matplotlib and PyQt5 works good, but there is one thing I don't like: bulky margins around axes area.
On the image that I have attached: top and bottom margins taking almost third part of all area. How can I make them smaller?
image
Code I using looks like:
from PyQt5 import QtCore, QtWidgets, QtGui
import matplotlib
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
from matplotlib import dates
class GraphWin(QtWidgets.QMainWindow):
def __init__(self, parent=None):
QtWidgets.QMainWindow.__init__(self, parent)
main_layout = QtWidgets.QHBoxLayout(self)
# graph area
self.graph = Figure()
self.graph.autofmt_xdate()
self.axis = self.graph.add_subplot(111)
self.canvas = FigureCanvas(self.graph)
main_layout.addWidget(self.canvas)
self.draw()
# draw function
def draw(self):
self.axis.plot(some_x, some_y, some_color, label=some_label)
fmt = dates.DateFormatter('%M:%S')
self.axis.xaxis.set_major_formatter(fmt)
self.axis.xaxis.set_major_locator(matplotlib.ticker.MaxNLocator(7))
self.axis.legend(loc=2)
self.axis.grid(b=True, which='both', color='#cccccc', linestyle='--')
self.canvas.draw()
This question differs from this because I would like to know how to adjust plot margins absolutely, e.g. in pixels or inches/cm not in percents like using function subplots_adjust().