Comments (9)
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.
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.
Ok, thanks @stevengj.
from pyplot.jl.
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.
Here is a gif of my Control Toolbox package that I was developing. I was really wanting this feature to have an interactive plot:
EDIT: I tested this with both Python 2 and 3 using Qt4, Qt5, and Tk as backend. Everything worked as expected!
from pyplot.jl.
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.
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.
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.
One question, did you install matplotlib from pip?
from pyplot.jl.
Related Issues (20)
- ticks = {Matrix} scuttles plot drawing HOT 3
- Error in Mac M1 HOT 2
- PyPlot does not display x and y coordinates
- __version__ not found when using PyPlot HOT 3
- twinx() and fgcolor issue HOT 2
- PyPlot Error
- Using PyPlot on CI suddenly fails HOT 1
- No working GUI backend found for matplotlib HOT 5
- unrelated println statement leads to blank plot
- getp not defined? HOT 1
- The show() method doesn't seem to work. HOT 2
- Window requires focus before functions return HOT 4
- Using the backend :qt not working HOT 1
- using PyPlot hangs/kills julia 1.8.5 or 1.9.0 on MacOS HOT 4
- Unable to install PyPlot (ResolvePackageNotFound conda error) HOT 2
- PyPlot.jl as a dependency breaks package registration? HOT 4
- ResolvePackageNotFound error in Ubuntu/Linux HOT 3
- `using PyPlot` crashes package precompilation on Julia v1.10.0-beta1 HOT 4
- Need a new release (Julia 1.10 PkgEval) HOT 2
- Qt: Session management error on linux
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyplot.jl.