JuliaMusic / MusicVisualizations.jl

Providing music-related visualization built on top of the packages of JuliaMusic
MIT License
17 stars 4 forks source link

Plot with Makie #5

Closed aminya closed 3 years ago

aminya commented 4 years ago

Using Plots instead of PyPlot allows using other backends such as GR which are much faster than PyPlot

Datseris commented 4 years ago

That is correct, but on the other hand it dissallows interactivity: PyPlot has basic interactive features, such as setting up events that trigger once you click on the plot.

For me this is important that these features exist, as I use them in my work.

To the best of my knowledge an alternative that can still offer this is Makie, but I don't think it is anywhere near ready of being a dependency yet.

aminya commented 4 years ago

Plots can use PyPlot as its backend too. I can check if the interactive features are supported in Plots

Datseris commented 4 years ago

Probably not. Here is the code I use in one of my scientific projects for interaction:

axp, axd = plot_piano_drums(piano, drums; grid = nothing, fi = Inf, st = st)
        axp.set_title("$(trio)_$(piece)_$(task) | init_ibi = $(init_ibi)")

        function onclick(event)
            if event.button == 3 # mouse right click
                println("-------------------")
            elseif event.button == 1 # mouse left click
                x,y,xx,yy = event.x, event.y, event.xdata, event.ydata
                println("$(round(Int, xx)),")
            end
        end

        fig = gcf()
        cid = fig.canvas.mpl_connect("button_press_event", onclick)

as you see, this requires the PyCall interface of PyPlot, as I need to be able to access the Python fields of the objects.

aminya commented 4 years ago

By quickly doing some search InspectDR has interactive capabilities (should check if the same functionality is supported), but more importantly, I should see if these are supported inside Plots. https://docs.juliaplots.org/latest/backends/ Wrapping everything inside Plots allows a smooth transition to other backends if one supports the same functionality later.

Datseris commented 4 years ago

Probably the best approach is to do this with Makie. It also allows for different backends, but has innate interactiveness and is massively faster.

Datseris commented 4 years ago

(but also keep the PyPlot code here)

aminya commented 4 years ago

Probably not. Here is the code I use in one of my scientific projects for interaction:

axp, axd = plot_piano_drums(piano, drums; grid = nothing, fi = Inf, st = st)
        axp.set_title("$(trio)_$(piece)_$(task) | init_ibi = $(init_ibi)")

        function onclick(event)
            if event.button == 3 # mouse right click
                println("-------------------")
            elseif event.button == 1 # mouse left click
                x,y,xx,yy = event.x, event.y, event.xdata, event.ydata
                println("$(round(Int, xx)),")
            end
        end

        fig = gcf()
        cid = fig.canvas.mpl_connect("button_press_event", onclick)

as you see, this requires the PyCall interface of PyPlot, as I need to be able to access the Python fields of the objects.

I do not find this in the repository. Where have you used it?

aminya commented 4 years ago

There are some interactions here: http://makie.juliaplots.org/dev/interaction.html

Is it OK to use the keyboard instead of mouse buttons? In Makie, there is one event for mouse click but not differentiated betwen left and right. Going with keyboard also gives more options.

dir = lift(scene.events.keyboardbuttons) do but
    global last_dir
    ispressed(but, Keyboard.left) && return 1
    ispressed(but, Keyboard.up) && return 2
    ispressed(but, Keyboard.right) && time[] += 1
    ispressed(but, Keyboard.down) && return 0
    last_dir
end
Datseris commented 4 years ago

I do not find this in the repository. Where have you used it?

It is private scientific project.


So I think the best way forward is to not remove PyPlot. I use it and I see no argument on why it should "go down". The Makie stuff should be extra, not a replacement.

In makie there is definitely differentiation between the different mouseclicks because I have used it at least once in InteractiveChaos.jl. But maybe it is not documented well, you should open an issue.

aminya commented 4 years ago

I got the answer in this issue. Makie supports all the keyboard and mouse buttons! https://github.com/JuliaPlots/AbstractPlotting.jl/blob/master/src/interaction/iodevices.jl

aminya commented 4 years ago

So I think the best way forward is to not remove PyPlot. I use it and I see no argument on why it should "go down". The Makie stuff should be extra, not a replacement.

I prefer to use Makie and have PyPlot as an extra. Having PyCall and PyPlot as a dependency is a pain. We can use Requires to make PyPlot optional

Datseris commented 4 years ago

Hm then I think the best way forward is that both are behind a Requires block.

Because I would assume that we would want to use same function names irrespectively of the plotting package.

chakravala commented 4 years ago

I also think that Makie and PyPlot are quite good, but I'd prefer not use them through Plots.jl

aminya commented 4 years ago

I also think that Makie and PyPlot are quite good, but I'd prefer not use them through Plots.jl

Makie is not supported through Plots anyway. But If PyPlot interaction were supported, Plots could be a very good interface

Datseris commented 4 years ago

By talking to the Makie developers recently, Makie package is heading towards a stable and robust interface, while keeping all performance and interactivity. I am thus renaming this, as it would soon allow using Makie here quite easily.

Datseris commented 3 years ago

closing in favor of #13