PyPlot.jl icon indicating copy to clipboard operation
PyPlot.jl copied to clipboard

add_callback fails on axis

Open timholy opened this issue 5 years ago • 0 comments
trafficstars

I'm trying to set up a callback that runs every time the user changes the zoom setting on an axis. Here's a demo in Python:

>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> fig, ax = plt.subplots()
>>> ax.plot(np.random.rand(5))
[<matplotlib.lines.Line2D object at 0x7fb3c34266d8>]
>>> def callback(artist):
...     print('callback')
... 
>>> ax.xaxis.add_callback(callback)
0
>>> plt.show()
callback
callback

and then if I click on the magnifying glass and zoom in, I get another callback exactly as expected.

However, here I get nothing:

julia> using PyPlot

julia> PyPlot.version
v"3.3.1"

julia> fig, ax = plt.subplots()
(Figure(PyObject <Figure size 640x480 with 1 Axes>), PyObject <AxesSubplot:>)

julia> ax.plot(rand(5))
1-element Vector{PyCall.PyObject}:
 PyObject <matplotlib.lines.Line2D object at 0x7f5d58079df0>

julia> called = []   # in case there are any task-switching concerns...
Any[]

julia> pushtime(args...) = push!(called, time())  # just log that we got called
pushtime (generic function with 1 method)

julia> ax.xaxis.add_callback(pushtime)
0

and called never gets populated no matter what I do.

Any suggestions? EDIT: true for both Julia 1.5.2 and Julia v"1.6.0-DEV.1187".

timholy avatar Oct 14 '20 12:10 timholy