# Is there a way to write a coordinate plane on top of an image?

**URL:** https://discourse.julialang.org/t/is-there-a-way-to-write-a-coordinate-plane-on-top-of-an-image/77796
**Category:** Visualization
**Tags:** images, makie
**Created:** [March 12, 2022, 3:42pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-write-a-coordinate-plane-on-top-of-an-image/77796 "2022-03-12T15:42:30Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![matic\_lauko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/matic_lauko/32/27770_2.png) [@matic\_lauko](https://discourse.julialang.org/u/matic_lauko)
#### Post date: [March 12, 2022, 3:42pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-write-a-coordinate-plane-on-top-of-an-image/77796/1 "2022-03-12T15:42:31Z")

</div>

Is there a way to write a coordinate plane on an image? And be able to get some coordinates of some points. The second part is not necessary.  
Thank you.

---

<div class="post-metadata">

### Author: ![lawless-m](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lawless-m/32/30869_2.png) [@lawless-m](https://discourse.julialang.org/u/lawless-m)
#### Post date: [March 14, 2022, 8:43am UTC](https://discourse.julialang.org/t/is-there-a-way-to-write-a-coordinate-plane-on-top-of-an-image/77796/2 "2022-03-14T08:43:34Z")

</div>

What kind of image?

You can draw whatever you like using Luxor

[http://juliagraphics.github.io/Luxor.jl/stable/](http://juliagraphics.github.io/Luxor.jl/stable/)

---

<div class="post-metadata">

### Author: ![empet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/empet/32/221303_2.png) [@empet](https://discourse.julialang.org/u/empet)
#### Post date: [March 14, 2022, 10:27am UTC](https://discourse.julialang.org/t/is-there-a-way-to-write-a-coordinate-plane-on-top-of-an-image/77796/3 "2022-03-14T10:27:49Z")

</div>

It’s not quite clear what you mean by “write a coordinate plane on an image”.  
Is it something like this?

```julia
using PlotlyJS

url ="https://raw.githubusercontent.com/empet/Texture-mapping-with-Plotly/main/images/sun-flower.jpg"
layout = Layout(width=400, height=400, 
                xaxis_range=[-2, 2], 
                yaxis=attr(range=[-2,2],
                           tickvals=-2:2, 
                           ticktext=-2:2), #set vertical and horizontal lines at equal distance
    images = [
        attr(
            source=url,
            xref="paper", 
            yref="paper",
            x=0, #fix image at the upper left corner
            y=1,
            xanchor="left",
            yanchor="top",
            sizex=1,
            sizey=1,
            layer="below",
            sizing="stretch")]);

pl = Plot(scatter(x=[-2,2], y=[-2, 2], 
                  mode="markers", marker_size=0.05), #dummy scatter plot 
          layout)

```

![equal](https://global.discourse-cdn.com/julialang/original/3X/d/d/dd8ff3ddcaf6ec2a46e836b5756c9a35a6991c34.png)

---

<div class="post-metadata">

### Author: ![matic\_lauko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/matic_lauko/32/27770_2.png) [@matic\_lauko](https://discourse.julialang.org/u/matic_lauko)
#### Post date: [March 15, 2022, 4:59am UTC](https://discourse.julialang.org/t/is-there-a-way-to-write-a-coordinate-plane-on-top-of-an-image/77796/4 "2022-03-15T04:59:51Z")

</div>

Thank you, that is exactly what I want, but is there a way to do this with Makie.jl and to include smaller numbers in between, like 1.123. So that it would be easier to read coordinates?

---

<div class="post-metadata">

### Author: ![icweaver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/icweaver/32/45764_2.png) [@icweaver](https://discourse.julialang.org/u/icweaver)
#### Post date: [March 15, 2022, 7:42am UTC](https://discourse.julialang.org/t/is-there-a-way-to-write-a-coordinate-plane-on-top-of-an-image/77796/5 "2022-03-15T07:42:20Z")

</div>

Here’s one way (using `translate!` to move the image behind the grid lines):

```julia
using CairoMakie, FileIO
img = load(download("https://raw.githubusercontent.com/empet/Texture-mapping-with-Plotly/main/images/sun-flower.jpg"))

f, ax, im = image(img;
	axis = (
		# x stuff	
		xticks = LinearTicks(10),
		xgridcolor = :white,
		xminorticksvisible = true,
		xminorgridvisible = true,
		xminorgridcolor = :black,
		# y stuff	
		yticks = LinearTicks(10),
		ygridcolor = :white,
		yminorticksvisible = true,
		yminorgridvisible = true,
		yminorgridcolor = :cornflowerblue,
		# Aspect ratio
		aspect = 1,
	)
)

translate!(im, 0, 0, -100)

f

```

This can also be wrapped into a [theme](https://makie.juliaplots.org/v0.15.2/documentation/theming/index.html) if you like:

```julia
img_theme = Theme(
	Axis = (
		# x stuff	
		xticks = LinearTicks(5),
		xminorticks = IntervalsBetween(4),
		xgridcolor = :black,
		xminorticksvisible = true,
		xminorgridvisible = true,
		xminorgridcolor = :white,
		# y stuff	
		yticks = LinearTicks(5),
		yminorticks = IntervalsBetween(4),
		ygridcolor = :black,
		yminorticksvisible = true,
		yminorgridvisible = true,
		yminorgridcolor = :cornflowerblue,
		# Aspect ratio
		aspect = 1,
	)
)

with_theme(img_theme) do
	f, ax, im = image(img)
	translate!(im, 0, 0, -100)
	f
end

```

 ![index](https://global.discourse-cdn.com/julialang/original/3X/7/b/7b5293a8f06e1296e415959ac14a98471f4a5b56.png)

and the white space can be removed by setting the [aspect ratio](https://makie.juliaplots.org/dev/tutorials/aspect-tutorial/index.html) this way instead:

```julia
with_theme(img_theme) do
	f, ax, im = image(img)
	translate!(im, 0, 0, -100)
	colsize!(f.layout, 1, Aspect(1, 1.0))
	resize_to_layout!(f)
	f
end

```

 ![index2](https://global.discourse-cdn.com/julialang/original/3X/3/7/379618dd5bc972bc064ddaa99dbe78cbb81cd73e.png)

According to the docs at least, it looks like minor tick labels [have not been implemented](https://makie.juliaplots.org/stable/examples/layoutables/axis/index.html#minor_ticks_and_grids), but it might be worth opening an issue for this as discussed here ([[Feature Request] - Minor ticks · Issue #822 · MakieOrg/Makie.jl · GitHub](https://github.com/JuliaPlots/Makie.jl/issues/822#issuecomment-769684652))

---

<div class="post-metadata">

### Author: ![matic\_lauko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/matic_lauko/32/27770_2.png) [@matic\_lauko](https://discourse.julialang.org/u/matic_lauko)
#### Post date: [March 19, 2022, 11:00am UTC](https://discourse.julialang.org/t/is-there-a-way-to-write-a-coordinate-plane-on-top-of-an-image/77796/6 "2022-03-19T11:00:34Z")

</div>

I had tried that, it works quite well however it rotates image by 90 degrees why is that so?

---

<div class="post-metadata">

### Author: ![matic\_lauko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/matic_lauko/32/27770_2.png) [@matic\_lauko](https://discourse.julialang.org/u/matic_lauko)
#### Post date: [March 19, 2022, 11:46am UTC](https://discourse.julialang.org/t/is-there-a-way-to-write-a-coordinate-plane-on-top-of-an-image/77796/7 "2022-03-19T11:46:39Z")

</div>

I fixed it by rotating an image before, how do you save an image, I have tried with save(f, "location.jpg), but doesn’t work. I haven’t found anything else.  
Thanks.

---

<div class="post-metadata">

### Author: ![icweaver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/icweaver/32/45764_2.png) [@icweaver](https://discourse.julialang.org/u/icweaver)
#### Post date: [March 19, 2022, 2:51pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-write-a-coordinate-plane-on-top-of-an-image/77796/8 "2022-03-19T14:51:59Z")

</div>

> however it rotates image by 90 degrees why is that so?

Oh, sorry, I should have rotated the image first in the above example, as you mentioned. For the long saga on default orientations check out [here](https://github.com/JuliaPlots/Makie.jl/issues/205) and [here](https://github.com/JuliaPlots/Makie.jl/issues/295). I believe there is an open PR for `image` ([Logical image() argument names & defaults to make images look like images · Issue #524 · MakieOrg/Makie.jl · GitHub](https://github.com/JuliaPlots/Makie.jl/issues/524)), but no sure what the current status on that is

> how do you save an image, I have tried with save(f, "location.jpg), but doesn’t work

Just flip the args ([https://makie.juliaplots.org/stable/documentation/figure\_size/index.html](https://makie.juliaplots.org/stable/documentation/figure_size/index.html))

---

<div class="post-metadata">

### Author: ![matic\_lauko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/matic_lauko/32/27770_2.png) [@matic\_lauko](https://discourse.julialang.org/u/matic_lauko)
#### Post date: [March 20, 2022, 7:03am UTC](https://discourse.julialang.org/t/is-there-a-way-to-write-a-coordinate-plane-on-top-of-an-image/77796/9 "2022-03-20T07:03:57Z")

</div>

Thank you, that helped a lot!
