nluigi
nluigi

Reputation: 1345

Cannot import matplotlib in Paraview

I am trying to make a figure using matplotlib in Paraview as discussed on page 73 of the user manual. I am running Paraview 5.2.0 64-bit on Windows 10. A minimal example is:

def setup_data(view):
    pass

def render(view, width, height):
    from paraview import python_view
    figure = python_view.matplotlib_figure(width, height)
    ax = figure.add_subplot(1,1,1)
    return python_view.figure_to_image(figure)

This however results in a black screen in the Python view and the following error in the output window:

Error: Cannot import matplotlib.backends.backend_agg.FigureCanvasAgg

Error: Cannot import matplotlib.figure.Figure

How to fix this?

Upvotes: 2

Views: 832

Answers (1)

nluigi
nluigi

Reputation: 1345

In my case, it turns out that matplotlib fails to load when it cannot import the dateutil module during import of the agg backend. Running pvpython and specifically importing the agg backend from matplotlib yields:

>>> import matplotlib.backends.backend_agg
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files\ParaView 5.2.0-Qt4-OpenGL2-Windows-64bit\bin\lib\site-packages\matplotlib\backends\backend_agg.py", line 31, in <module>
    from matplotlib.figure import Figure
  File "C:\Program Files\ParaView 5.2.0-Qt4-OpenGL2-Windows-64bit\bin\lib\site-packages\matplotlib\figure.py", line 18, in <module>
    from axes import Axes, SubplotBase, subplot_class_factory
  File "C:\Program Files\ParaView 5.2.0-Qt4-OpenGL2-Windows-64bit\bin\lib\site-packages\matplotlib\axes.py", line 19, in <module>
    import matplotlib.dates as mdates
  File "C:\Program Files\ParaView 5.2.0-Qt4-OpenGL2-Windows-64bit\bin\lib\site-packages\matplotlib\dates.py", line 119, in <module>
    from dateutil.rrule import rrule, MO, TU, WE, TH, FR, SA, SU, YEARLY, \
ImportError: No module named dateutil.rrule

Specifically importing dateutil shows it is not installed:

>>> import dateutil
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named dateutil

Unfortunately, my pvpython runs version 2.7.3 so pip is not installed by default and i found installing pip to be difficult with pvpython in Windows 10. Instead, i downloaded python-dateutil 2.6.0 and extracted only the folder dateutil from the zip archive into the pvpython library folder located at:

C:\Program Files\ParaView 5.2.0-Qt4-OpenGL2-Windows-64bit\bin\lib\site-packages\

Restarting Paraview then gave me a figure in the Python view instead of a black screen.

Upvotes: 2

Related Questions