# Luxor questions

**URL:** https://discourse.julialang.org/t/luxor-questions/41946
**Category:** Visualization
**Created:** [June 23, 2020, 4:13pm UTC](https://discourse.julialang.org/t/luxor-questions/41946 "2020-06-23T16:13:24Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![turtle](https://avatars.discourse-cdn.com/v4/letter/t/ecb155/32.png) [@turtle](https://discourse.julialang.org/u/turtle)
#### Post date: [June 23, 2020, 4:13pm UTC](https://discourse.julialang.org/t/luxor-questions/41946/1 "2020-06-23T16:13:24Z")

</div>

I have started learning `Luxor.jl`, and I find it great.

I would have two questions:

1. Can I reverse the default coordinate system somehow?  
(_i.e._ x axis to the right, but y axis upwards)
2. Can I use LaTeX expressions as text?

---

<div class="post-metadata">

### Author: ![lobingera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lobingera/32/211_2.png) [@lobingera](https://discourse.julialang.org/u/lobingera)
#### Post date: [June 23, 2020, 7:43pm UTC](https://discourse.julialang.org/t/luxor-questions/41946/2 "2020-06-23T19:43:28Z")

</div>

For the coordinate system i’d recommend to read the [http://juliagraphics.github.io/Luxor.jl/stable/transforms/](http://juliagraphics.github.io/Luxor.jl/stable/transforms/)  
(i’d guess that for inverting an axis scale(1,-1) should work)  
For the LaTeX expressions i’ve not seen a Luxor usable way; the Makie plotting supports rendered LaTeX expressions by displaying real tex output, but i’ve lost track if this is reusable in other places.

---

<div class="post-metadata">

### Author: ![turtle](https://avatars.discourse-cdn.com/v4/letter/t/ecb155/32.png) [@turtle](https://discourse.julialang.org/u/turtle)
#### Post date: [June 23, 2020, 9:02pm UTC](https://discourse.julialang.org/t/luxor-questions/41946/3 "2020-06-23T21:02:06Z")

</div>

Thank you for the solution, `scale(1,-1)` works indeed.

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [June 24, 2020, 7:05am UTC](https://discourse.julialang.org/t/luxor-questions/41946/4 "2020-06-24T07:05:11Z")

</div>

I found that

[https://github.com/KristofferC/PGFPlotsX.jl](https://github.com/KristofferC/PGFPlotsX.jl)

works fine for simple drawings that need LaTeX (with the axes turned off, you just get a canvas). Basically Tikz/PGF with a Julia-ish interface for coordinates.

---

<div class="post-metadata">

### Author: ![turtle](https://avatars.discourse-cdn.com/v4/letter/t/ecb155/32.png) [@turtle](https://discourse.julialang.org/u/turtle)
#### Post date: [June 24, 2020, 7:18am UTC](https://discourse.julialang.org/t/luxor-questions/41946/5 "2020-06-24T07:18:09Z")

</div>

Thank you for the pointer to your LaTeX friendly package.

---

<div class="post-metadata">

### Author: ![turtle](https://avatars.discourse-cdn.com/v4/letter/t/ecb155/32.png) [@turtle](https://discourse.julialang.org/u/turtle)
#### Post date: [June 25, 2020, 9:30pm UTC](https://discourse.julialang.org/t/luxor-questions/41946/7 "2020-06-25T21:30:45Z")

</div>

Dear @lobingera and @cormullion, may I have an other newbie question.

The suggested `scale(1,-1)` transformation works well,  
providing the x axis to the right, and the y axis upwards.

However, if any text is added then it gets mirrored and becomes unreadable.  
Is there a solution to this problem?

---

<div class="post-metadata">

### Author: ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)
#### Post date: [June 25, 2020, 9:46pm UTC](https://discourse.julialang.org/t/luxor-questions/41946/8 "2020-06-25T21:46:44Z")

</div>

You could write your own text function that temporarily (use `gsave` or `@layer`) resets the scale, draw the text, then returns things back to upside down.

Although I’d recommend just using the coordinate system as it is, rather than fight it… 😀

---

<div class="post-metadata">

### Author: ![turtle](https://avatars.discourse-cdn.com/v4/letter/t/ecb155/32.png) [@turtle](https://discourse.julialang.org/u/turtle)
#### Post date: [June 25, 2020, 9:57pm UTC](https://discourse.julialang.org/t/luxor-questions/41946/9 "2020-06-25T21:57:42Z")

</div>

I badly need the standard Cartesian coordinate system, so I need to fight.  
But you are right, this code seems to work:

```julia
function mytext(str,x,y)
    gsave()
    scale(1,-1)
    text(str,x,-y)
    grestore()
end

```

---

<div class="post-metadata">

### Author: ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)
#### Post date: [June 25, 2020, 10:09pm UTC](https://discourse.julialang.org/t/luxor-questions/41946/10 "2020-06-25T22:09:12Z")

</div>

```julia
function mytext(str, pos; kwargs...)
    @layer begin
        translate(pos)
        scale(1, -1)
        text(str, O; kwargs...)
    end
end

@draw begin
    fontsize(30)
    scale(1, -1)
    rulers()
    mytext("0/0", Point(0, 0))
    mytext("160/160", Point(160, 160), halign=:center)
end

```

 ![Screenshot 2020-06-25 at 23.08.24](https://global.discourse-cdn.com/julialang/original/3X/0/3/03b98ce54db3c3c3d15d7d979152b55f91e6aeae.png)

This should work - but I wouldn’t recommend it… 🙂

---

<div class="post-metadata">

### Author: ![turtle](https://avatars.discourse-cdn.com/v4/letter/t/ecb155/32.png) [@turtle](https://discourse.julialang.org/u/turtle)
#### Post date: [June 25, 2020, 10:15pm UTC](https://discourse.julialang.org/t/luxor-questions/41946/11 "2020-06-25T22:15:27Z")

</div>

Thank you for all your help.  
But why is it so strange that someone wants to use  
the standard Cartesian coordinate system for drawing geometry?  
(_e.g._ to use your great `Luxor.jl` package instead of `GeoGebra`)

---

<div class="post-metadata">

### Author: ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)
#### Post date: [June 25, 2020, 10:19pm UTC](https://discourse.julialang.org/t/luxor-questions/41946/12 "2020-06-25T22:19:42Z")

</div>

It’s not that it’s strange - just that I don’t know whether everything will work correctly if you work upside down. (Things like arcs will be “backwards”, won’t they?)

Working from the top left is fairly standard in computer graphics, if not maths… For example, SVG, HTML, images, arrays, many illustration applications, all start at the top left… True, there’s PostScript which is the obvious bottom-left exception…

If you’re happy to be the pioneer, I’m always here to help… 🙂

---

<div class="post-metadata">

### Author: ![StevenSiew](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevensiew/32/218393_2.png) [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)
#### Post date: [June 25, 2020, 10:20pm UTC](https://discourse.julialang.org/t/luxor-questions/41946/13 "2020-06-25T22:20:28Z")

</div>

The solution is very easy. Just transform your coordinate system to the Luxor coordinate system

Let x,y be the luxor coordinate system  
Let xx,yy be your coordinate system

x = xx  
y = (CanvasHeight - 1) - yy

It’s that easy!

---

<div class="post-metadata">

### Author: ![turtle](https://avatars.discourse-cdn.com/v4/letter/t/ecb155/32.png) [@turtle](https://discourse.julialang.org/u/turtle)
#### Post date: [June 25, 2020, 10:38pm UTC](https://discourse.julialang.org/t/luxor-questions/41946/14 "2020-06-25T22:38:39Z")

</div>

Up to now I did not experience a problem with `arc2r`, `carc2r`, `sector`, `pie` _etc_.  
Text was the first case, where I have run into a serious problem.

---

<div class="post-metadata">

### Author: ![turtle](https://avatars.discourse-cdn.com/v4/letter/t/ecb155/32.png) [@turtle](https://discourse.julialang.org/u/turtle)
#### Post date: [June 25, 2020, 10:43pm UTC](https://discourse.julialang.org/t/luxor-questions/41946/15 "2020-06-25T22:43:22Z")

</div>

Thank you.  
And what is the transformation after the `origin()` command?  
Also it seems to me that any such transformation requires a large number  
of extra function calls, in contrast to a single `scale(1,-1)` setting.

---

<div class="post-metadata">

### Author: ![StevenSiew](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevensiew/32/218393_2.png) [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)
#### Post date: [June 25, 2020, 11:00pm UTC](https://discourse.julialang.org/t/luxor-questions/41946/16 "2020-06-25T23:00:11Z")

</div>

After the origin() command is just a translation

x = xo + (CanvasWidth/2)  
y = yo + (CanvasHeight/2)

do the transformation x = xx and y = (CanvasHeight - 1) - yy

xx = xo + (CanvasWidth/2)  
(CanvasHeight - 1) - yy = yo + (CanvasHeight/2)

Next do some rearrangement

xo = xx - (CanvasWidth/2)  
yo = (CanvasHeight - 1) - yy - (CanvasHeight/2)

So now you can convert from your coordinate to xo,yo

And if you want to use xxo,yyo instead of your xx,yy then

xx = xxo + (CanvasWidth/2)  
yy = yyo + (CanvasHeight/2)

Next do the substitution

xo = (xx) - (CanvasWidth/2)  
yo = (CanvasHeight - 1) - (yy) - (CanvasHeight/2)

to

xo = (xxo + (CanvasWidth/2)) - (CanvasWidth/2)  
yo = (CanvasHeight - 1) - (yyo + (CanvasHeight/2)) - (CanvasHeight/2)

and do some cleanup

xo = xxo  
yo = -1 - yyo
