Customising MPL in PyQt
<p>So I've been doing a great deal of research in to PyQt and MPL, and I'm still having some issues that I can't get past. </p>

<p><strong>The first is this</strong>: How do you change the FigureCanvas background color (it's the gray part in <a href="http://i.stack.imgur.com/etvHq.jpg" rel="nofollow">this image</a>). FigureCanvas does not have attributes for facecolor or backgroundcolor or anything else I can think of or find. I can change color on the axes, the plots (that's how I got the black background you can see), but not the canvas itself. </p>

<p><strong>Second problem:</strong> How can I get rid of the mouse pointer that is still visible over the top of the crosshairs? Or better yet change the cursor when it enters the mpl FigureCanvas widget (and consequently back again when it leaves).</p>

<p><strong>EDIT:</strong> Here is some of my code as requested. I am calling MPL figures from Qt via the following.</p>

<p>My main window:</p>

<pre><code>from PyQt5.QtCore import pyqtSlot as Slot
from PyQt5 import QtCore
from PyQt5 import QtWidgets
from PyQt5 import QtGui
from PyQt5 import uic

# MPL class
from pyqt5_mpl import mpl_figure

# Select Qt5 user interface.
qtCreatorFile = '&lt;local filepath&gt;'
Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile)

class main(QtWidgets.QMainWindow, Ui_MainWindow):

    def __init__(self):
        # Inititate UI.
        QtWidgets.QMainWindow.__init__(self)
        Ui_MainWindow.__init__(self)
        self.setupUi(self)

        # Create data structures.
        global a
        a = a_dataclass()

        # Create MPL Canvases (Layout-&gt;CreateMPLCanvas-&gt;AddWidget).
        # Create class instances for each figure.
        a.im1 = mpl_figure()
        a.im2 = mpl_figure()

        # Create Layouts and add widgets.
        a_layout = QtWidgets.QHBoxLayout(self.tab1)
        a_layout.addWidget(a.im1.canvas)
        a_layout.addWidget(a.im2.canvas)

        # Load images.
        a.im1.loadimage('image file path',a.pix)
        a.im2.loadimage('image file path',a.pix)
        # a.pix is dimensions for extent in plot.

if __name__ == "__main__":
    # QApp 
    app = QtWidgets.QApplication(sys.argv)
    # QWidget (MainWindow)
    window = main()
    window.show()
    sys.exit(app.exec_())
</code></pre>

<p>My mpl_figure class:</p>

<pre><code>import matplotlib as mpl
mpl.use('Qt5Agg')
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas

class mpl_figure:

    def __init__(self):
        # Set up empty plot variables.
        self.image = None
        # Create a figure to plot on.
        fig = plt.figure()
        fig.set_facecolor('black') # This does nothing...
        # Create an axis in the figure.
        self.ax = fig.add_subplot(111, axisbg='black')
        # Create a canvas widget for Qt to use.
        self.canvas = FigureCanvas(fig)
        # Create cursor widget.
        self.cursor = mpl.widgets.Cursor(self.ax)
        # Refresh the canvas.
        self.canvas.draw()

    def loadimage(self,fn,pix):
        # Read in image.
        self.data = plt.imread(fn)
        # Calculate the extent.
        self.dims = np.array([0, pix[0]*np.shape(self.data)[1],0,pix[1]*np.shape(self.data)[0]])
        # Display the image.
        self.image = self.ax.imshow(self.data, cmap='gray', extent=self.dims)
        self.ax.set_autoscale_on(False)
        # Refresh the canvas.
        self.canvas.draw()
        # Start Callback ID
        self.cid = self.canvas.mpl_connect('button_press_event', self.onclick)

    def onclick(self,event):
        # Do stuff...
        pass
</code></pre>

<p>All my attempts to try and make changes to self.canvas or fig. in terms of its styling are rendered mute and it does nothing. And as far as changing the cursor (or hiding it, it being the pointer) when you enter an mpl_widget I'm just not sure on how to do it. I remember seeing something within mpl that was to the effect of connect "event_leave_figure", but couldn't make a connection between that and PyQt &lt;- that's the important bit. Any ideas?</p>

<p>Thanks for providing a <a href="http://stackoverflow.com/help/mcve">MINIMAL WORKING example</a> and for googling before asking a question. That always saves a lot of time. </p>

<p>So the following code produces the image shown below.</p>

<pre><code>import sys
from PyQt4 import QtGui, QtCore
import matplotlib 
import numpy as np
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure


class ApplicationWindow(QtGui.QMainWindow):
    def __init__(self):
        QtGui.QMainWindow.__init__(self)
        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
        self.setWindowTitle("application main window")

        self.main_widget = QtGui.QWidget(self)
        self.setCentralWidget(self.main_widget)
        l = QtGui.QVBoxLayout(self.main_widget)

        self.fig = Figure(figsize=(5,3), dpi=100)
        self.ax = self.fig.add_subplot(111)
        self.canvas = FigureCanvas(self.fig)
        l.addWidget(self.canvas)

        t = np.arange(0.0, 3.0, 0.01)
        s = np.sin(2*np.pi*t)*np.exp(-t/7/np.pi)
        self.ax.plot(t, s, color="#0095a2", lw=3)

        #set some alpha
        self.fig.patch.set_alpha(0.5)
        #set color
        self.fig.patch.set_facecolor('#cd0e49')

        self.cursor = matplotlib.widgets.Cursor(self.ax)
        #set cursor
        #self.canvas.setCursor(QtGui.QCursor(QtCore.Qt.BlankCursor))
        #since I find Blank cursor very confusing, I will use a better one:
        self.canvas.setCursor(QtGui.QCursor(    QtCore.Qt.SizeAllCursor))



qApp = QtGui.QApplication(sys.argv)

aw = ApplicationWindow()
aw.show()
sys.exit(qApp.exec_())
</code></pre>

<p><a href="http://i.stack.imgur.com/k8koY.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/k8koY.jpg" alt="enter image description here"></a></p>

python matplotlib pyqt5