检查数据
|
该页面正在翻译中。 |
Makie通过以下方式提供数据检查工具 数据探测器(x) 其中x可以是图形,轴或场景。 通过将鼠标悬停在其中一个元素上,您可以获得一个浮动工具提示,其中包含各种绘图的相关信息。
默认情况下,检查器将能够选择除 文本 和 卷数 基于地块。 如果你想忽略一个情节,你可以设置它的属性 情节。检查[]=错误. 有了这个,下一个最近的情节(在范围内)将被挑选。
#
<无翻译>*麦琪数据探测仪*-Type</无翻译>
DataInspector(figure_axis_or_scene = current_figure(); kwargs...)
创建一个数据检查器,当您将鼠标悬停在绘图上时,它将在工具提示中显示相关信息。
通过设置,可以在每个绘图的基础上禁用此功能 情节。检查[]=错误. 显示的文本可以通过设置进行调整 情节。检查器_label 到函数 (图、索引、位置)->"my_label" 返回标签。 有关更多详细信息,请参阅Makie文档。
关键字参数:
-
范围=10:控制用于选择绘图元素的捕捉范围。 -
优先级=100:在鼠标移动或滚动事件上创建工具提示的优先级。 -
启用=真:设置为false时禁用对绘图的检查。 也可以调整与启用!(督察)和禁用!(督察). -
indicator_color=:红色:选择指示器的颜色。 -
indicator_linewidth=2:选择指标的线宽。 -
indicator_linestyle=无:选择指标的Linestyle -
enable_indicators=true):启用或禁用指标 -
深度=9e3:工具提示的深度值。 这应该很高,以便工具提示始终在前面。 -
apply_tooltip_offset=true:启用或禁用基于例如markersize的偏移工具提示。 -
和所有属性从
工具提示
自定义文本
该文本 数据探测仪 显示可以通过调整每个情节的基础上 检查器_label 属性。 它应该有一个功能 (图、索引、位置)->"my_string",在哪里 情节 标签正在调整的情节, 索引 索引是否由 挑选 (请参阅事件文档)和 职位 是被检查物的位置。
lbls = ["Type A", "Type B"]
fig, ax, p = scatter(
rand(10), color = rand(1:2, 10), colormap = [:red, :blue],
inspector_label = (self, i, p) -> lbls[self.color[][i]]
)
DataInspector(fig)
fig
延伸;延伸 数据探测仪
检查器为基本图和一些非基本图(即配方)实现工具提示。 所有其他图都回退到其中一个子图的工具提示。
例如a 保利 由一个 网格;网格 和一个 线框/线框 情节,在哪里 线框/线框 被实现为 线条. 因为两者都没有 保利 也没有 线框/线框 有专门的 显示_数据 方法,DataInspector使用任 网格;网格 或 线条 生成工具提示。
虽然这意味着大多数绘图都有工具提示,但也意味着许多绘图可能没有合适的工具提示。 如果您希望为新的绘图类型实现更合适的工具提示,可以通过扩展来实现
function show_data(inspector::DataInspector, my_plot::MyPlot, idx, primitive_child::SomePrimitive)
...
end
这里 我的绘图 是要为其创建自定义工具提示的绘图, 原始儿童 你的绘图是由(散点、文本、线条、线、网格、表面、体积、图像或热图)和 idx 是原始图的索引。 后两者是从 摘取/摘取 在当前鼠标位置。 一般来说,你需要调整 idx 对……有用。 我的计划.
让我们来看看 [医]条形图 方法,这也权力 哈斯特. 它包含两个原始图 - 网格;网格 和 线条. 该 idx 从挑选一个 网格;网格 是基于顶点,其中每个矩形有四个。 从 线条 我们根据一条线的终点得到一个索引. 要像在barplot中那样绘制矩形的轮廓,我们需要5个点和一个总计为6的分隔符。 因此,我们实施
import Makie: show_data
function show_data(inspector::DataInspector, plot::BarPlot, idx, ::Lines)
return show_barplot(inspector, plot, div(idx-1, 6)+1)
end
function show_data(inspector::DataInspector, plot::BarPlot, idx, ::Mesh)
return show_barplot(inspector, plot, div(idx-1, 4)+1)
end
映射图元 idx 一个识别酒吧的人 [医]条形图. 有了这个,我们现在可以得到悬浮杆的位置 情节[1][idx]. 为了使工具提示与选择对齐,我们需要计算屏幕空间中的相关位置并更新工具提示位置。
using Makie: parent_scene, shift_project, update_tooltip_alignment!, position2string
function show_barplot(inspector::DataInspector, plot::BarPlot, idx)
# Get the tooltip plot
tt = inspector.plot
# Get the scene BarPlot lives in
scene = parent_scene(plot)
# Get the hovered data-space position
pos = plot[1][][idx]
# project to screen space and shift it to be correct on the root scene
proj_pos = shift_project(scene, to_ndim(Point3f, pos, 0))
# anchor the tooltip at the projected position
update_tooltip_alignment!(inspector, proj_pos)
# Update the final text of the tooltip.
if haskey(plot, :inspector_label)
tt.text[] = plot[:inspector_label][](plot, idx, pos)
else
tt.text[] = position2string(pos)
end
# Show the tooltip
tt.visible[] = true
# return true to indicate that we have updated the tooltip
return true
end
接下来我们要标记我们悬停的矩形。 在这种情况下,我们可以使用矩形 [医]条形图 传递给 保利,即 情节。图[1][1][idx]. 该 数据探测仪 包含一些用于跟踪临时图的功能,因此我们可以将指标绘制为相同的 场景 那个 [医]条形图 用途。 这样做会导致
using Makie:
parent_scene, shift_project, update_tooltip_alignment!, position2string,
clear_temporary_plots!
function show_data(inspector::DataInspector, plot::BarPlot, idx)
# inspector.attributes holds some attributes relevant to indicators and is
# used as a cache for indicator observables
a = inspector.attributes
tt = inspector.plot
scene = parent_scene(plot)
pos = plot[1][][idx]
proj_pos = shift_project(scene, plot, to_ndim(Point3f, pos, 0))
update_tooltip_alignment!(inspector, proj_pos)
# We only want to mark the rectangle if that setting is enabled
if a.enable_indicators[]
# Get the relevant rectangle
bbox = plot.plots[1][1][][idx]
# If we haven't yet created an indicator create it
if inspector.selection != plot
# clear old indicators
clear_temporary_plots!(inspector, plot)
# Create the new indicator using some settings from `DataInspector`.
p = wireframe!(
scene, bbox, model = plot.model[], color = a.indicator_color,
strokewidth = a.indicator_linewidth, linestyle = a.indicator_linestyle,
visible = a.indicator_visible, inspectable = false
)
# tooltips are pushed forward a certain amount to make sure they're
# drown on top of other things. This indicator should also be pushed
# forward that much
translate!(p, Vec3f(0, 0, a.depth[]))
# Keep track of the indicator plot
push!(inspector.temp_plots, p)
# If we have already created an indicator plot we just need to update
# it. In this case we only need to update the rectangle.
elseif !isempty(inspector.temp_plots)
p = inspector.temp_plots[1]
p[1][] = bbox
end
# Moving away from a plot will automatically set this to false, so we
# always need to set it to true.
a.indicator_visible[] = true
end
if haskey(plot, :inspector_label)
tt.text[] = plot[:inspector_label][](plot, idx, pos)
else
tt.text[] = position2string(pos)
end
tt.visible[] = true
return true
end
完成自定义工具提示的实现 [医]条形图.