The syntax for using PyPlot in Julia is a bit different from Python.
This is a result of the fact that (currently) you cannot use obj.f()
to access the method (function) f()
inside an object obj
in Julia, which PyPlot uses heavily.
To get around this, obj.f()
in Python is replaced by obj[:f]()
in Julia; note the :
.
So ax.spines
in Python becomes
ax[:spines]
in Julia.
As noted by the other poster, you must first do ax = gca()
to store the current axis object in the variable ax
.
If you do this at the Julia REPL or in a Jupyter notebook, you will see
julia> ax = gca()
PyObject <matplotlib.axes._subplots.AxesSubplot object at 0x31f854550>
julia> ax[:spines]
Dict{Any,Any} with 4 entries:
"left" => PyObject <matplotlib.spines.Spine object at 0x31f854c10>
"bottom" => PyObject <matplotlib.spines.Spine object at 0x31f854f50>
"right" => PyObject <matplotlib.spines.Spine object at 0x31f854dd0>
"top" => PyObject <matplotlib.spines.Spine object at 0x31f86e110>
showing that ax[:spines]
is a dictionary. (I did not previously know about this. This is the advantage of having an interactive session -- you can just ask Julia what you need to know. This is called "introspection".)
Following the Python answer linked to in the original question, you then need to replace ax.spines['left'].set_position('zero')
in Python by the following in Julia:
ax[:spines]["left"][:set_position]("zero")
Again, the set_position
method inside the object ax[:spines]["left"]
is called. Note also that strings in Julia must have "
, not '
.