RM-
RM-

Reputation: 1008

PyPlot Error in Julia: type PyObject has no field set_yscale

I am programming in Julia but using PyPloy library. I want to plot an histogram with log y-axis. But when I use the following code:

using PyPlot
List = [rand() for i = 1:100]
plt.hist(List)
plt.gca().set_yscale("log")

I get the following error:

type PyObject has no field set_yscale
while loading In[45], in expression starting on line 3

 in getindex at /home/rm/.julia/v0.4/PyCall/src/PyCall.jl:642
 in pysequence_query at /home/rm/.julia/v0.4/PyCall/src/conversions.jl:743
 in pytype_query at /home/rm/.julia/v0.4/PyCall/src/conversions.jl:759
 in convert at /home/rm/.julia/v0.4/PyCall/src/conversions.jl:808
 in pycall at /home/rm/.julia/v0.4/PyCall/src/PyCall.jl:812
 in fn at /home/rm/.julia/v0.4/PyCall/src/conversions.jl:181
 in close_queued_figs at /home/rm/.julia/v0.4/PyPlot/src/PyPlot.jl:295

Is this a path error? If so, is there a simpler way to do a log-log plot with a different command?

Thanks in advance.

Upvotes: 3

Views: 1663

Answers (1)

Bill Gross
Bill Gross

Reputation: 516

I feel like this should be more prominently explained in the documentation, but if you scroll down to the bottom of the Readme for PyCall (which PyPlot uses) it says:

Important: The biggest difference from Python is that object attributes/members are accessed with o[:attribute] rather than o.attribute, so that o.method(...) in Python is replaced by o[:method](...)

So, as @jverzani mentioned, after you call any module-level function from PyPlot that returns an object, that object is a PyObject and all of the attributes and methods have to be called using the bracket notation with a symbol.

Upvotes: 2

Related Questions