JuliaPy / PyPlot.jl

Plotting for Julia based on matplotlib.pyplot
https://github.com/JuliaPy/PyPlot.jl
MIT License
475 stars 87 forks source link

ERROR: 'PyCall.jlwrap' object has no attribute 'replace' #486

Closed cossio closed 4 years ago

cossio commented 4 years ago

julia> using SequenceLogos: SequenceLogo, SequenceLogoSite, WeightedLetter

julia> logo = SequenceLogo([
         SequenceLogoSite([WeightedLetter('A', 0.5), WeightedLetter('F', 0.2)]),
         SequenceLogoSite([WeightedLetter('G', 0.75), WeightedLetter('H', 0.1)])])
SequenceLogo(SequenceLogoSite[SequenceLogoSite(WeightedLetter[WeightedLetter('A', 0.5), WeightedLetter('F', 0.2)]), SequenceLogoSite(WeightedLetter[WeightedLetter('G', 0.75), WeightedLetter('H', 0.1)])])

julia> plot_sequence_logo(logo)
ERROR: PyError ($(Expr(:escape, :(ccall(#= /home/cossio/.julia/packages/PyCall/zqDXB/src/pyfncall.jl:43 =# @pysym(:PyObject_Call), PyPtr, (PyPtr, PyPtr, PyPtr), o, pyargsptr, kw))))) <class 'AttributeError'>
AttributeError("'PyCall.jlwrap' object has no attribute 'replace'")
  File "/home/cossio/.julia/conda/3/lib/python3.7/site-packages/matplotlib/textpath.py", line 457, in __init__
    s, ismath = Text(usetex=usetex)._preprocess_math(s)
  File "/home/cossio/.julia/conda/3/lib/python3.7/site-packages/matplotlib/text.py", line 1197, in _preprocess_math
    return s.replace(r"\$", "$"), False

Stacktrace:
 [1] pyerr_check at /home/cossio/.julia/packages/PyCall/zqDXB/src/exception.jl:60 [inlined]
 [2] pyerr_check at /home/cossio/.julia/packages/PyCall/zqDXB/src/exception.jl:64 [inlined]
 [3] _handle_error(::String) at /home/cossio/.julia/packages/PyCall/zqDXB/src/exception.jl:81
 [4] macro expansion at /home/cossio/.julia/packages/PyCall/zqDXB/src/exception.jl:95 [inlined]
 [5] #110 at /home/cossio/.julia/packages/PyCall/zqDXB/src/pyfncall.jl:43 [inlined]
 [6] disable_sigint at ./c.jl:446 [inlined]
 [7] __pycall! at /home/cossio/.julia/packages/PyCall/zqDXB/src/pyfncall.jl:42 [inlined]
 [8] _pycall!(::PyCall.PyObject, ::PyCall.PyObject, ::Tuple{Tuple{Float64,Int64},Char}, ::Int64, ::PyCall.PyObject) at /home/cossio/.julia/packages/PyCall/zqDXB/src/pyfncall.jl:29
 [9] _pycall!(::PyCall.PyObject, ::PyCall.PyObject, ::Tuple{Tuple{Float64,Int64},Char}, ::Base.Iterators.Pairs{Symbol,Any,Tuple{Symbol,Symbol},NamedTuple{(:size, :prop),Tuple{Int64,PyCall.PyObject}}}) at /home/cossio/.julia/packages/PyCall/zqDXB/src/pyfncall.jl:11
 [10] #_#117 at /home/cossio/.julia/packages/PyCall/zqDXB/src/pyfncall.jl:86 [inlined]
 [11] letter_at(::Char, ::Tuple{Int64,Float64}, ::Float64, ::PyCall.PyObject) at /home/cossio/work/RBMpro/jl/SequenceLogos.jl/src/pyplot.jl:73
 [12] plot_sequence_logo(::SequenceLogo; ax::Nothing, show_fig::Bool, figsize::Tuple{Int64,Int64}) at /home/cossio/work/RBMpro/jl/SequenceLogos.jl/src/pyplot.jl:55
 [13] plot_sequence_logo(::SequenceLogo) at /home/cossio/work/RBMpro/jl/SequenceLogos.jl/src/pyplot.jl:43
 [14] top-level scope at REPL[16]:1

where SequenceLogos is defined here: https://github.com/cossio/SequenceLogos.jl

stevengj commented 4 years ago

Python doesn't have a character type, so PyCall translates Char to a Julia wrapper class.

You pass letter::Char to TextPath, but matplotlib is expecting a string. Pass string(letter).

cossio commented 4 years ago

Ok, thanks for taking a look!