Julia charting interaction

2019-08-16 03:33发布

问题:

I am looking for a Julia charting package that allows the user to click on a point in the chart (a bar in a barplot for example). Then send an event that I can interactively receive and interpret which bar was clicked on to then produce another chart of whatever I would like.

I have found interactive Julia packages which go the other way. Put a widget on the screen and the user can change a slider for example to change chart. But not clicking on chart.

回答1:

PyPlot wraps matplotlib, and matplotlib supports event handling. Read the matplotlib event handling docs here. This is has all the functionality from their first example translated into Julia. You may want to refer to the [PyCall docs]2 to read about the pyobject[:symbol] syntax.

julia> using PyPlot
julia> fig=figure()
PyPlot.Figure(PyObject <matplotlib.figure.Figure object at 0x1159d3f90>)
julia> function onclick(event)
       println(event)
       println((event[:xdata],event[:ydata],event[:x],event[:y]))
       end
onclick (generic function with 1 method)
julia> fig[:canvas][:mpl_connect]("button_press_event",onclick)
6
julia> PyObject <matplotlib.backend_bases.MouseEvent object at 0x131d5d110>
(nothing, nothing, 385, 388.0)
PyObject <matplotlib.backend_bases.MouseEvent object at 0x131d5d410>
(nothing, nothing, 365, 256.0)
PyObject <matplotlib.backend_bases.MouseEvent object at 0x131d5d3d0>
(nothing, nothing, 429, 337.0)

The last six lines are from me clicking randomly on the blank figure that appeared. I suggest looking at the "Object Picking" section.



标签: charts julia