Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[solved] Importing matplotlib within a) an inline script and/or b) the Pyhton code for a plugin

edited January 2014 in OpenSesame

Hi all,

To be able to draw circles that are additions and substractions to eachother (see below or here - btw: I didn't add 'vd' to the url, imageshack did...), I can't simply use the canvas 'circle'-function, but I use Pyhton code instead (for which I translated of one of my Matlab-functions, but it works fine in PythonWin). This code makes a 2D-array and draws it so the screen by using the matplotlib 'show' and 'matshow' commands. When I try importing matplotlib (simply by using 'import matplotlib as mpl'), however, the folowing error occurs:

Error: Inline script error

In: inline_script (run phase)
File "matplotlib__init__.pyo", line 495, in _get_data_path

Python traceback:
AttributeError: 'module' object has no attribute 'afm'

And the following in the debugwindow:

Traceback (most recent call last):<br /> File "libopensesame\inline_script.pyo", line 112, in run<br /> File "<string>", line 2, in <module><br /> File "matplotlib&#95;_init__.pyo", line 765, in <module><br /> File "matplotlib&#95;_init__.pyo", line 683, in rc_params<br /> File "matplotlib&#95;_init__.pyo", line 599, in matplotlib_fname<br /> File "matplotlib&#95;_init__.pyo", line 246, in wrapper<br /> File "matplotlib&#95;_init__.pyo", line 520, in _get_data_path_cached<br /> File "matplotlib&#95;_init__.pyo", line 495, in _get_data_path<br /> AttributeError: 'module' object has no attribute 'afm'

I've checked the library, but 'afm.pyo' really is in there. Curiously, importing numpy in the same fashion ('import numpy as np') works perfectly well,

What am I doing wrong and is there another way to put 2D-arrays on the screen?

Many thanks in advance!

Image 1 - an image as created by my function: 20 circles with a random size (between 50 and 250 px) and a random colour, added and substracted from eachother (colormap is gray, with vmin=-130 and vmax=130)



  • edited 2:32PM

    Hi Edwin,

    I checked it, and it appears that some parts of matplotlib are missing from the OpenSesame windows packages. It is not uncommon (but very annoying) for some dependencies to go missing (or break) when creating packages with py2exe. There's not much that can be done about it without repackaging it. Incidentally, matplotlib does appear to work with your own Portable OpenSesame!

    There are lots of ways to perform these types of drawing operations. Using NumPy in combination with PyGame surfarrays, using PIL (Python imaging), using matplotlib (I suppose, haven't tried it), and using PsychoPy. I would personally tend to go for PsychoPy, because it's faster, but it's mostly down to personal preference.

    Good luck!


    There's much bigger issues in the world, I know. But I first have to take care of the world I know.

Sign In or Register to comment.