[GIS] Issue using Matplotlib in QGIS

matplotlibpythonqgis

I am developing a QGIS-plugin and for graphing I want to use matplotlib, like many other QGIS -plugins.

This worked fine under linux, but under windows with QGIS2.4 I am experiencing problems.

I checked and matplotlib seams to be included in the standard windows-install of QGIS. But when people try to install the plugin, they get this report:

The plugin is broken: No Module named tkinter

Turns out even though I'm using pyqt, matplotlib requires tkinter and this seams be to be excluded from the QGIS installation.

Is this a Bug? (should i report it?)

Or is there a way to use matplotlib without loading tkinter?

If I really need tkinter, how can I solve this? As tkinter is a binary python package, i can't include it in my plugin or is there an alternative (pyQWT is also binary, so also not a solution)

I call matplotlib this way:

from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar
import matplotlib.pyplot as plt

its the experimental version (1.2.0) of this plugin, if you want to try it:
http://plugins.qgis.org/plugins/geopunt4Qgis/

Best Answer

OK i found the problem. I made following changes to my code so it doesn't try load tkinter anymore:

I changed:

  import matplotlib.pyplot as plt

into:

  from matplotlib.figure import Figure
  from matplotbib import axes

and change plt.figure() in Figure() etc..

Related Question