Giter Club home page Giter Club logo

Comments (9)

ronisbr avatar ronisbr commented on June 16, 2024

I do really need to connect a signal in fig[:canvas] using fig[:canvas][:mpl_connect]. However, I am getting this same error message. I am trying to get the position of a mouse click over a plot. Is there any way to solve the problem now?

Thanks,
Ronan

from pyplot.jl.

stevengj avatar stevengj commented on June 16, 2024

This is due to JuliaPy/PyCall.jl#158, and looks like it requires some implementation work in PyCall to support Python weak references to Julia objects.

from pyplot.jl.

ronisbr avatar ronisbr commented on June 16, 2024

Ok, thanks @stevengj.

from pyplot.jl.

ronisbr avatar ronisbr commented on June 16, 2024

@stevengj

Hi! Did something change? I was able to connect an event to a Julia function using the fig[:canvas][:mpl_connect] without problems. The weak reference error does not show anymore.

Here is an example:

using PyCall
pygui(:qt5)
using PyPlot

function test(event)
    println("Click: $(event[:xdata]), $(event[:ydata])")
end

fig = figure()
plot(0:1:10, 0:1:10)
fig[:canvas][:mpl_connect]("button_press_event", test)

Then, after clicking on the figure, I see:

julia> Click: 4.423387096774194, 4.476190476190478
Click: 5.820564516129033, 4.11904761904762
Click: 1.806451612903226, 7.2738095238095255
Click: 3.691532258064516, 7.690476190476192
Click: 6.286290322580645, 7.660714285714288
Click: 7.572580645161291, 5.30952380952381
Click: 5.997983870967743, 2.7202380952380962
Click: 1.5625, 3.7916666666666674
Click: 0.941532258064516, 6.708333333333336

from pyplot.jl.

ronisbr avatar ronisbr commented on June 16, 2024

Here is a gif of my Control Toolbox package that I was developing. I was really wanting this feature to have an interactive plot:

rlocus

EDIT: I tested this with both Python 2 and 3 using Qt4, Qt5, and Tk as backend. Everything worked as expected!

from pyplot.jl.

lukasfischer83 avatar lukasfischer83 commented on June 16, 2024

What Julia/PyCall version were you using for that? Did you also test on linux?
I still get the same "weak reference" error in 0.6.2 and after a Pkg.update() on ubuntu.

from pyplot.jl.

ronisbr avatar ronisbr commented on June 16, 2024

I was using Julia 0.6.2 and latest released version of PyCall in openSUSE linux. I tested it on macOS and Linux. In linux, I performed a test using different versions of Python and QT5. Everything worked. You can see this package here:

https://github.com/ronisbr/ControlToolbox.jl

from pyplot.jl.

lukasfischer83 avatar lukasfischer83 commented on June 16, 2024

Unfortunately in my setup (ubuntu 14.04, tried Python 3.4 and 2.7) it also doesn't work with your example.

rlocus(G)
ERROR: PyError (ccall(@pysym(:PyObject_Call), PyPtr, (PyPtr, PyPtr, PyPtr), o, arg, C_NULL)) <class 'TypeError'>
TypeError("cannot create weak reference to 'PyCall.jlwrap' object",)
  File "/usr/lib/python3/dist-packages/matplotlib/backend_bases.py", line 2324, in mpl_connect
    return self.callbacks.connect(s, func)
  File "/usr/lib/python3/dist-packages/matplotlib/cbook.py", line 495, in connect
    self._func_cid_map[s][func] = cid
  File "/usr/lib/python3.4/weakref.py", line 365, in __setitem__
    self.data[ref(key, self._remove)] = value

Stacktrace:
 [1] pyerr_check at /home/lukas/.julia/v0.6/PyCall/src/exception.jl:58 [inlined]
 [2] pyerr_check at /home/lukas/.julia/v0.6/PyCall/src/exception.jl:62 [inlined]
 [3] macro expansion at /home/lukas/.julia/v0.6/PyCall/src/exception.jl:82 [inlined]
 [4] #_pycall#88(::Array{Any,1}, ::Function, ::PyCall.PyObject, ::String, ::Vararg{Any,N} where N) at /home/lukas/.julia/v0.6/PyCall/src/PyCall.jl:710
 [5] _pycall(::PyCall.PyObject, ::String, ::Vararg{Any,N} where N) at /home/lukas/.julia/v0.6/PyCall/src/PyCall.jl:698
 [6] #pycall#92(::Array{Any,1}, ::Function, ::PyCall.PyObject, ::Type{PyCall.PyAny}, ::String, ::Vararg{Any,N} where N) at /home/lukas/.julia/v0.6/PyCall/src/PyCall.jl:732
 [7] pycall(::PyCall.PyObject, ::Type{PyCall.PyAny}, ::String, ::Vararg{Any,N} where N) at /home/lukas/.julia/v0.6/PyCall/src/PyCall.jl:732
 [8] #call#93(::Array{Any,1}, ::PyCall.PyObject, ::String, ::Vararg{Any,N} where N) at /home/lukas/.julia/v0.6/PyCall/src/PyCall.jl:735
 [9] (::PyCall.PyObject)(::String, ::Vararg{Any,N} where N) at /home/lukas/.julia/v0.6/PyCall/src/PyCall.jl:735
 [10] plot_rlocus(::Array{Array{Complex{Float64},1},1}, ::Array{Float64,1}, ::Array{Complex{Float64},1}, ::Array{Complex{Float64},1}, ::Array{Complex{Float64},1}, ::Array{Complex{Float64},1}) at /home/lukas/.julia/v0.6/ControlToolbox/src/plots/plot_rlocus.jl:45
 [11] #rlocus#22(::Bool, ::Function, ::ControlToolbox.TransferFunction, ::Array{Any,1}) at /home/lukas/.julia/v0.6/ControlToolbox/src/analysis/rlocus.jl:222
 [12] rlocus(::ControlToolbox.TransferFunction) at /home/lukas/.julia/v0.6/ControlToolbox/src/analysis/rlocus.jl:27

from pyplot.jl.

ronisbr avatar ronisbr commented on June 16, 2024

One question, did you install matplotlib from pip?

from pyplot.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.