3

I have embedded a matplotlib plot in my GUI like this:

from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas

fig = DataPlot()
self.canvas = FigureCanvas(fig)
self.vL_Frame.addWidget(self.canvas)    
self.canvas.draw()

For the desired functionality of this plot, it is important know the actual cursor position in this plot → x and y position like in the default toolbar. As I just need the cursor position and none of the icons of the default toolbar, I made my own toolbar like this (which I found here: How to modify the navigation toolbar easily in a matplotlib figure window?):

from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar

class MyToolbar(NavigationToolbar):
    # only display the buttons we need
    toolitems = [t for t in NavigationToolbar.toolitems if
             t[0] in ()]

    def __init__(self, *args, **kwargs):
        super(MyToolbar, self).__init__(*args, **kwargs)
        self.layout().takeAt(0)

self.toolbar = MyToolbar(self.canvas, self)
self.vL_cursor_Frame.addWidget(self.toolbar)

With that I got my cursor position, but it is 'cut' somehow. I use quotation marks, because I know that it happens because I don't show the icons from the default toolbar. This is my result I couldn't make a screenshot with shown cursor position, but it appears next to the 'Save' button.

Does anyone know how to show the full cursor position? And how to delete this frame or shadow around my cursor position/customized toolbar? Thank you in advance :)

Community
  • 1
  • 1
Gaudium
  • 31
  • 3

0 Answers0