首页 > 解决方案 > Add tag with coordinates to plot in Plots.jl

问题描述

I have a plot with intersecting lines:

Plot

And I would like to add a tag or pointer which point to the intersection and display the coordinates of the intersection. Something like this:

Tag example

I know the coordinates of the intersection and I know that the function annotate! adds text to the plot. However, I do not know how to add a line or arrow to point to the intersection and how to determine the right position for the text.

标签: juliaplots.jl

解决方案


我同意这不是最用户友好的事情,但我认为它也不是那么容易实现(实际上,当我在实践中这样做时,我经常诉诸于仅导出到 PowerPoint,然后手动注释绘图) - 但这是一种方法:

julia> using Plots

julia> plot(x -> x^2, 0:0.01:2); hline!([1], color = :red, linestyle = :dash); vline!([1], color = :green, linestyle = :dash)

julia> quiver!([0.5], [2], quiver = ([0.475], [-0.95]))

julia> annotate!([0.5], [2.1], text("This point is (1,1)"), valign = :top)

在此处输入图像描述


推荐阅读