Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fonsp/3b42ff393662d222f6eaf7a02135bc56 to your computer and use it in GitHub Desktop.
Save fonsp/3b42ff393662d222f6eaf7a02135bc56 to your computer and use it in GitHub Desktop.

Fons van der Plas:pluto:1 day ago

Plots.jl - Is there a way to go from an image coordinate (e.g. (300,200) for the centre of a 600x400 rendered plot) to the corresponding space coordinate?The reason I'm asking is that Pluto can do some cool tricks, including self-updating interactive plots. Here's a demo of a phase plot where you can click to set the initial value: fonsp/Pluto.jl#582 (comment) wrote that plot using d3.js, but if Plots.jl would support this coordinate conversion it could open the door to some very cool stuff (edited)

img

Simon Christ1 day ago

I don't think we already have some, but I also don't think it is too hard to write it

img

Miles Lucas:star:19 hours ago

so if you do heatmap with an array the image gets plotted according to 1-index image coordinates, so your 600x400 image is from (1, 600) (1, 400) and the middle is (300.5, 200.5)so the conversion is just a translation once you find the center, if that’s your goal, or you can make a plot become an image by heatmapping the array and manually setting the axes according to the center and size you want

img

Daniel Schwabeneder13 hours ago

Not exactly what you asked for, but maybe this can be helpful.

julia> using Plotsjulia> plt = plot(rand(10))julia> p_box = bbox(plt.layout) # bounding box of total plot
BBox{l,t,r,b,w,h = 0.0mm,0.0mm, 152.4mm,101.6mm, 152.4mm,101.6mm}julia> sp_box = plotarea(plt[1]) # bounding box of first subplot
BBox{l,t,r,b,w,h = 9.419233757535165mm,3.0mm, 149.4mm,94.38944mm, 139.98076624246485mm,91.38944mm}julia> using Plots: left, top, width, heightjulia> get_center(box) = (left(box) + width(box) / 2, top(box) + height(box) / 2)
get_center (generic function with 1 method)julia> get_center(p_box)
(76.2mm, 50.8mm)julia> get_center(sp_box)
(79.4096168787676mm, 48.69472mm)

(edited)

img

Simon Christ13 hours ago

Only thing that is missing is scaling with the axis limits

:+1:1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment