4

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?

2 Answers 2

6

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') 
Sign up to request clarification or add additional context in comments.

1 Comment

I was using TkAgg and this solution works perfectly.
4

I'm not aware of a backend-independent way to do that, but there are various backend-specific solutions. For example, for the Qt backend you could use QWidget.setFixedSize:

import matplotlib matplotlib.use("Qt4Agg") from matplotlib import pyplot as plt fig, ax = plt.subplots(1, 1) win = fig.canvas.window() win.setFixedSize(win.size()) plt.show() 

To fix the size of the canvas drawing area rather than the whole window you could use fig.canvas.setFixedSize instead.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.