0
votes

I was trying to reproduce this example from the matplotlib website using the PyPlot package for Julia. As far as I know, the PyPlot is essentialy the matplotlib.pyplot module, so I imported the other modules of matplotlib that I needed (with the @pyimport macro):

using PyCall

@pyimport matplotlib.path as mpath

@pyimport matplotlib.patches as mpatches

Then I proceed to define the path object:

Path = mpath.Path

but then I get:

fn (generic function with 1 method) .

As if I had defined a function. Moreover, when I assign the path_data I get the following error:

ERROR: type Function has no field MOVETO

Of course, that's due to Path, which Julia tries as a function and not as a type or something like that. As you might guess the same happens when I try to define the variable patch .

So, there are incompatibilities of modules from matplotlib different to pyplot for Julia since the expected objects (types) are taken as functions. This behaviour can be expected if it were different the PyPlot.jl file wouldn't be needed.

My questions are:

-Am I doing something wrong?

-Is there a simple way to make it works?

-Do you know another package for Julia in which I can define patches and work in a similar way to matplotlib?

I have in mind to do this kind of animations.

Thanks for your ideas.

1

1 Answers

1
votes

You need to get the "raw" Python object for Path. By default, PyCall converts Python type objects into functions (which call the corresponding constructor), but then you cannot access static members of the class.

Instead, do e.g. Path = mpath.pymember("Path") to get the "raw" PyObject, and then you can do Path["MOVETO"] or Path[:MOVETO] to access the MOVETO member.

(This difficulty will hopefully go away in Julia 0.4 once something like https://github.com/JuliaLang/julia/pull/8008 gets merged (so that we can make PyObjects callable directly.)