Remove frame on canvas (Matplotlib backend_qt5agg)

I’m building an application on PyQt5 with Matplotlib embbeded. When I display the figure and move it around with Matplotlib’s toolbar, it leaves a frame, and the figure hides behind its limmits.

I’m having trouble figuring out how to remove this frame and ploting the image centralized on the widget itself. So overall, I would like to remove the frames and plot the image centralized on the white area.

Here is an example on the problem. If someone could help, I would appeciate it :slight_smile:

This is the expected behavior. The image has some extent within an Axes, the pan tool changes the view limits of the Axes, so as you pan part of the image may move out of the view limits but the Axes stays in place relative to the Figure (Quick start guide — Matplotlib 3.6.2 documentation is a good place to look for a glossary of the terms Matplotlib uses).

It looks like you have turned off all of the ticks and tick labels, if you leave those in place the behavior would be clearer.

Without any code it is hard to guess what the easiest way for you get what you want is, but I suggest looking at either Figure.figimage or making the Axes fill the whole Figure.

@tacaswell Thanks for the reply. This is the code I have so far:

class Mpl_Widget(QWidget):
    # constructor
    def __init__(self, parent=None):
        super(Mpl_Widget, self).__init__(parent)
        self.path_salvar = None

        self.canvas = FigureCanvas(Figure())
        self.toolbar = NavigationToolbar(self.canvas, self)
        layout = QVBoxLayout()
    # opens the image
    def abrir_imagem(self):
        arquivo = QFileDialog.getOpenFileName(self, "Abrir Arquivo", os.getcwd(), "DICOM Files (*.dcm)")
        if arquivo:

            self.ds = pydicom.dcmread(arquivo[0], force=True)
            self.ds.file_meta.TransferSyntaxUID = '1.2.840.10008.1.2.1'
            self.imagem = self.ds.pixel_array

            ax = self.canvas.figure.add_subplot(111, frame_on=False)
            ax.tick_params(left = False, right = False , labelleft = False ,
                labelbottom = False, bottom = False)
            ax.imshow(self.imagem, cmap='gray')

The main things would be plotting it closer to the top of the widget or, as you suggested, make the axis fill the entire figure. But I’m having trouble figuring out how to do both.