Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I lock matplotlib window resizing

I'm working on an open source project that involves mouse interaction (via mpl_connect) with a scatter plot using pyplot in matplotlib. I was able to disable the bottom toolbar from appearing with:

matplotlib.rcParams['toolbar'] = 'None'

But I haven't found anything similar for locking the width/height of the window and disabling resizing. (Currently, the clickable areas are calculated on startup and do not change if the window is resized.) Is there a way to disable resizing for now until I implement a version that allows resizing without breaking?

like image 405
Mattie Avatar asked Oct 26 '25 20:10

Mattie


1 Answers

Matplotlib supports several backends. To see what backend you're using (I have TkAgg):

>>> pyplot.get_backend()
u'TkAgg'

Backend can be one of GTKAgg, GTK3Agg, GTK, GTKCairo, GTK3Cairo, WXAgg, WX, TkAgg, Qt4Agg, Qt5Agg, macosx (see http://matplotlib.org/faq/usage_faq.html#what-is-a-backend).

With a TkAgg backend you can prevent a window from resizing in width and height using resizable(False, False) (http://www.tkdocs.com/tutorial/windows.html)

from matplotlib import pyplot

bck = pyplot.get_backend()
print "Backend is " + bck
mng = pyplot.get_current_fig_manager()
if (bck == "TkAgg"):   
    mng.window.resizable(False, False)
elif (bck == "QT4Agg"):
    print "See previous answer"
else:
    print "?"

If you have the required packages installed you can switch backends using for instance

>>> pyplot.switch_backend('QT4Agg')
like image 188
user2314737 Avatar answered Oct 28 '25 09:10

user2314737



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!