简体   繁体   English

我如何在 Makie 中点击 select 一行?

[英]How do I select a line by clicking in Makie?

I want to be able to select a line on the plot by clicking on it.我希望能够通过单击 select 在 plot 上添加一行。 Ideally, when I click on any line, the number of that line will appear on the screen.理想情况下,当我单击任何一行时,该行的编号将出现在屏幕上。 I wrote my code based on the tutorial, but there is no example with lines, so I did what I did.我根据教程编写了我的代码,但是没有带行的示例,所以我做了我所做的。 https://docs.makie.org/v0.19/documentation/events/index.html#point_picking https://docs.makie.org/v0.19/documentation/events/index.html#point_picking

At the moment I have no idea what these numbers are telling me and why.目前我不知道这些数字告诉我什么以及为什么。 They are not even coordinates of clicked points.它们甚至不是点击点的坐标。

PS Actually it is just a starting point. PS 其实这只是一个起点。 I want to create event interaction on series and topoplots.我想在系列和 topoplots 上创建事件交互。 But for now it would be great to find out the basics.但就目前而言,找出基础知识会很棒。

f = Figure(backgroundcolor = RGBf(0.98, 0.98, 0.98), resolution = (1500, 700))
ax = Axis(f[1, 1], xlabel = "Time [s]", ylabel = "Voltage amplitude [µV]") 

N = 1:length(pos)
positions = Observable(rand(Point2f, 10))

xs = 0:0.01:10
ys = 0.5 .* sin.(xs)

lines!(xs, ys)
lines!(xs, ys * 2)

hidedecorations!(ax, label = false, ticks = false, ticklabels = false) 
hidespines!(ax, :t, :r) 
hlines!(0, color = :gray, linewidth = 1)
vlines!(0, color = :gray, linewidth = 1)

i = Observable(0)
on(events(f).mousebutton, priority = 2) do event
    if event.button == Mouse.left && event.action == Mouse.press
        plt, i[] = pick(f)
        str = lift(i -> "$(i)", i)
        text!(ax, 1, -0.5, text = str,  align = (:center, :center)) 
    end
end
f

Below are some examples of the interaction between clicking and the number displayed (the red dot is where I click).下面是点击和显示的数字之间交互的一些示例(红点是我点击的地方)。 在此处输入图像描述 在此处输入图像描述

Check out the mouseposition variable here:在此处查看 mouseposition 变量:

https://docs.makie.org/stable/api/#Events https://docs.makie.org/stable/api/#Events

or the registerInteraction: function here:或者 registerInteraction: function 在这里:

https://docs.makie.org/v0.19/examples/blocks/axis/index.html#registering_and_deregistering_interactions https://docs.makie.org/v0.19/examples/blocks/axis/index.html#registering_and_deregistering_interactions

You can use them both as below:您可以按以下方式使用它们:

using GLMakie

f = Figure(backgroundcolor = RGBf(0.98, 0.98, 0.98), resolution = (1500, 700))
ax = Axis(f[1, 1], xlabel = "Time [s]", ylabel = "Voltage amplitude [µV]") 

#N = 1:length(pos)
positions = Observable(rand(Point2f, 10))

xs = 0:0.01:10
ys = 0.5 .* sin.(xs)

lines!(xs, ys)
lines!(xs, ys * 2)

hidedecorations!(ax, label = false, ticks = false, ticklabels = false) 
hidespines!(ax, :t, :r) 
hlines!(0, color = :gray, linewidth = 1)
vlines!(0, color = :gray, linewidth = 1)

register_interaction!(ax, :my_interaction) do event, axis
    if event.type === MouseEventTypes.leftclick
        println("Graph axis position: $(event.data)")
    end
end

i = Observable(0)
on(events(f).mousebutton, priority = 2) do event
    if event.button == Mouse.left && event.action == Mouse.press
        plt, i[] = pick(f)
        str = lift(i -> "$(i)", i)
        text!(ax, 1, -0.5, text = str,  align = (:center, :center)) 
        @show mouseposition(f)
    end
end
f

Note that for some reason (perhaps it sees the first click as a selection?) Makie does not start registering the interaction on the graph until the first click within the graph, unlike the clicks on the figure which are all shown even the first one.请注意,出于某种原因(也许它将第一次点击视为选择?)Makie 直到在图表中第一次点击后才开始在图表上注册交互,这与图表上的点击不同,即使是第一次点击也会显示出来。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在不基于URL参数的情况下从YUI TabView中选择选项卡 - How can I select a tab from the YUI TabView without clicking it based on URL arguments 单击选项中的选项时,如何更改音频源? - How do you change the audio source when clicking on an option, from a select? jQuery如何选择多个元素 - jQuery how do i select multiple elements 为什么单击按钮时无法选择所有文本? - Why am I unable to select all the text when clicking a button? 单击跨度元素后如何允许用户更改跨度文本内容? - How do I allow a user to change span textcontent after clicking on the span element? 双击文本后如何使 li 元素可编辑(在 vanilla Javascript 中)? - How do I make an li element editable after double clicking the text (in vanilla Javascript)? 如何使用存储在数组中的select2对象事件? - How do I use select2 object events stored in an array? 如何使用href =“”#xyz”选择所有标签 - how do i select all a tags with href=“#xyz” 我可以通过单击按钮检测我触发了哪些 javascipt 函数吗? - Can I detect which javascipt functions do I trigger by clicking a button? 如何使select .change事件在失去焦点之前不会触发(最好使用jquery)? - How do I make a select .change event not fire until it loses focus (using jquery preferably)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM