Julia PyPlot: how to use multiple linestyles

Hello,
I am not quite into pyplot and I could not find a good tutorial (there is pyplot, but only for python).
I am trying to plot some results and I would like to use different linestyles. But I get an error:

myPlot = plot(x, y1, x, y2, x, w3,
                linestyle = [":", ":", "-"])
ERROR: PyError ($(Expr(:escape, :(ccall(#= /home/gigiux/.julia/packages/PyCall/BcTLp/src/pyfncall.jl:43 =# @pysym(:PyObject_Call), PyPtr, (PyPtr, PyPtr, PyPtr), o, pyargsptr, kw))))) <class 'ValueError'>
ValueError("Unrecognized linestyle: [':', ':', '-']")
  File "/home/gigiux/.julia/conda/3/lib/python3.8/site-packages/matplotlib/pyplot.py", line 2840, in plot
    return gca().plot(
  File "/home/gigiux/.julia/conda/3/lib/python3.8/site-packages/matplotlib/axes/_axes.py", line 1743, in plot
    lines = [*self._get_lines(*args, data=data, **kwargs)]
  File "/home/gigiux/.julia/conda/3/lib/python3.8/site-packages/matplotlib/axes/_base.py", line 273, in __call__
    yield from self._plot_args(this, kwargs)
  File "/home/gigiux/.julia/conda/3/lib/python3.8/site-packages/matplotlib/axes/_base.py", line 418, in _plot_args
    return [func(x[:, j % ncx], y[:, j % ncy], kw, kwargs)
  File "/home/gigiux/.julia/conda/3/lib/python3.8/site-packages/matplotlib/axes/_base.py", line 418, in <listcomp>
    return [func(x[:, j % ncx], y[:, j % ncy], kw, kwargs)
  File "/home/gigiux/.julia/conda/3/lib/python3.8/site-packages/matplotlib/axes/_base.py", line 312, in _makeline
    seg = mlines.Line2D(x, y, **kw)
  File "/home/gigiux/.julia/conda/3/lib/python3.8/site-packages/matplotlib/lines.py", line 363, in __init__
    self.set_linestyle(linestyle)
  File "/home/gigiux/.julia/conda/3/lib/python3.8/site-packages/matplotlib/lines.py", line 1141, in set_linestyle
    self._us_dashOffset, self._us_dashSeq = _get_dash_pattern(ls)
  File "/home/gigiux/.julia/conda/3/lib/python3.8/site-packages/matplotlib/lines.py", line 56, in _get_dash_pattern
    raise ValueError('Unrecognized linestyle: %s' % str(style))

Stacktrace:
 [1] pyerr_check at /home/gigiux/.julia/packages/PyCall/BcTLp/src/exception.jl:62 [inlined]
 [2] pyerr_check at /home/gigiux/.julia/packages/PyCall/BcTLp/src/exception.jl:66 [inlined]
 [3] _handle_error(::String) at /home/gigiux/.julia/packages/PyCall/BcTLp/src/exception.jl:83
 [4] macro expansion at /home/gigiux/.julia/packages/PyCall/BcTLp/src/exception.jl:97 [inlined]
 [5] #110 at /home/gigiux/.julia/packages/PyCall/BcTLp/src/pyfncall.jl:43 [inlined]
 [6] disable_sigint at ./c.jl:446 [inlined]
 [7] __pycall! at /home/gigiux/.julia/packages/PyCall/BcTLp/src/pyfncall.jl:42 [inlined]
 [8] _pycall!(::PyCall.PyObject, ::PyCall.PyObject, ::NTuple{6,Array{Float64,1}}, ::Int64, ::PyCall.PyObject) at /home/gigiux/.julia/packages/PyCall/BcTLp/src/pyfncall.jl:29
 [9] _pycall!(::PyCall.PyObject, ::PyCall.PyObject, ::NTuple{6,Array{Float64,1}}, ::Base.Iterators.Pairs{Symbol,Array{String,1},Tuple{Symbol},NamedTuple{(:linestyle,),Tuple{Array{String,1}}}}) at /home/gigiux/.julia/packages/PyCall/BcTLp/src/pyfncall.jl:11
 [10] pycall(::PyCall.PyObject, ::Type{PyCall.PyAny}, ::Array{Float64,1}, ::Vararg{Array{Float64,1},N} where N; kwargs::Base.Iterators.Pairs{Symbol,Array{String,1},Tuple{Symbol},NamedTuple{(:linestyle,),Tuple{Array{String,1}}}}) at /home/gigiux/.julia/packages/PyCall/BcTLp/src/pyfncall.jl:83
 [11] plot(::Array{Float64,1}, ::Vararg{Array{Float64,1},N} where N; kws::Base.Iterators.Pairs{Symbol,Array{String,1},Tuple{Symbol},NamedTuple{(:linestyle,),Tuple{Array{String,1}}}}) at /home/gigiux/.julia/packages/PyPlot/XHEG0/src/PyPlot.jl:177
 [12] top-level scope at none:1

It works if I give the same linestyle, so what is the correct syntax for multiple styles?
Also, it is possible to set (a) the color and (b) give transparency to the color?
Thank you

You cannot specify multiple linestyles in one plotting command. Try this instead:

plot(x, y1, linestyle = ":")
plot(x, y2, linestyle = ":")
plot(x, w3, linestyle = "-")

It’s also possible to have PyPlot automatically cycle between styles, see e.g. Styling with cycler — Matplotlib 3.1.2 documentation.

1 Like