# Y-axis reversed when using PyPlot.ylim

**URL:** https://discourse.julialang.org/t/y-axis-reversed-when-using-pyplot-ylim/66958
**Category:** New to Julia
**Created:** [August 25, 2021, 3:56am UTC](https://discourse.julialang.org/t/y-axis-reversed-when-using-pyplot-ylim/66958 "2021-08-25T03:56:25Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![SSU](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ssu/32/11306_2.png) [@SSU](https://discourse.julialang.org/u/SSU)
#### Post date: [August 25, 2021, 3:56am UTC](https://discourse.julialang.org/t/y-axis-reversed-when-using-pyplot-ylim/66958/1 "2021-08-25T03:56:25Z")

</div>

Y axis of pyplot turns upside down when using pyplot.ylim.  
Is this an expected behavior of PyPlot.jl?

By the way, are the indices of images/matrixes passed to PyPlot.jl converted to 0-origin?

Thank you in advance!!

**version**  
Julia: v1.6.0  
PyPlot: v2.9.0

**code**

```julia
using PyPlot, Images

img = rand(20, 20)
img[5, 5] = 255
imshow(img, cmap=plt.cm.gray)
scatter(4, 4, c="r")
# scatter(5, 5, c="r") did not match the point img[5, 5] = 255
savefig("test.png")

imshow(img, cmap=plt.cm.gray)
scatter(4, 4, c="r")
ylim(0, 19)
savefig("test2.png")

```

**output image**

1. test.png  
 ![test](https://global.discourse-cdn.com/julialang/original/3X/3/e/3eebd38e3d27c7cb605a8cb801f9fa300244f257.png)

2. test2.png  
 ![test2](https://global.discourse-cdn.com/julialang/original/3X/c/a/ca81efe7e8780ae7f3ffefd8472cc2b639dd1346.png)

---

<div class="post-metadata">

### Author: ![fgerick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fgerick/32/13228_2.png) [@fgerick](https://discourse.julialang.org/u/fgerick)
#### Post date: [August 25, 2021, 7:11am UTC](https://discourse.julialang.org/t/y-axis-reversed-when-using-pyplot-ylim/66958/2 "2021-08-25T07:11:04Z")

</div>

`imshow` has the y-axis order reversed compared to other 2-D plots like `contourf` or `pcolor` and `ylim` takes the lower and upper limit as inputs. What you want is `ylim(19,0)`. Like this the same order is kept and you can define limits.

---

<div class="post-metadata">

### Author: ![SSU](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ssu/32/11306_2.png) [@SSU](https://discourse.julialang.org/u/SSU)
#### Post date: [August 27, 2021, 1:24am UTC](https://discourse.julialang.org/t/y-axis-reversed-when-using-pyplot-ylim/66958/3 "2021-08-27T01:24:12Z")

</div>

Thank you.  
I didn’t know this specification at all.
