[solved] Importing matplotlib within a) an inline script and/or b) the Pyhton code for a plugin
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):
File "libopensesame\inline_script.pyo", line 112, in run
File "", line 2, in
File "matplotlib__init__.pyo", line 765, in
File "matplotlib__init__.pyo", line 683, in rc_params
File "matplotlib__init__.pyo", line 599, in matplotlib_fname
File "matplotlib__init__.pyo", line 246, in wrapper
File "matplotlib__init__.pyo", line 520, in _get_data_path_cached
File "matplotlib__init__.pyo", line 495, in _get_data_path
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!
Edwin
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)
Comments
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!
Cheers,
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!