# Why does Plots.jl require axis to be in ascending order?

**URL:** <https://discourse.julialang.org/t/why-does-plots-jl-require-axis-to-be-in-ascending-order/39926>\
**Category:** Tooling\
**Tags:** question, plotting\
**Created:** [May 22, 2020, 12:22am UTC](https://discourse.julialang.org/t/why-does-plots-jl-require-axis-to-be-in-ascending-order/39926 "2020-05-22T00:22:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fergu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fergu/32/14710_2.png) [@fergu](https://discourse.julialang.org/u/fergu)\
**Post date:** [May 22, 2020, 12:22am UTC](https://discourse.julialang.org/t/why-does-plots-jl-require-axis-to-be-in-ascending-order/39926/1 "2020-05-22T00:22:20Z")

</div>

I have some 2D data that effectively represents an image. This image also has spatial dimensions which are important, and those dimensions start in the top left. In python I’d use something like `plt.pcolor(x,y,z)` or similar to plot this data, where x and y are vectors and z is a 2D matrix with matching sizes in the appropriate dimensions. (Or I can do something like `X,Y = np.meshgrid(x,y)`).

It appears that `Plots.heatmap(x, y, z)` is what I’m looking for in Julia. However, it seems that Julia does not like that my coordinate values are in a decreasing order in one axis (the y axis) as I get a “y points not sorted in ascending order” error and the resulting plot is empty except for its axes (which appear correctly, actually).

I know it’s possible to sort the data in to ascending order, but this seems like a kind of odd restriction. Is there a reason for this, or am I misusing the interface?

Edit: I should add that the axis coordinates are linear (in fact formed using `y = a_y*range(0,stop=n_y)+b_y`) - just linearly decreasing instead of increasing in this case.

---

<div class="post-metadata">

**Author:** ![BeastyBlacksmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beastyblacksmith/32/4741_2.png) [@BeastyBlacksmith](https://discourse.julialang.org/u/BeastyBlacksmith)\
**Post date:** [May 22, 2020, 11:35pm UTC](https://discourse.julialang.org/t/why-does-plots-jl-require-axis-to-be-in-ascending-order/39926/2 "2020-05-22T23:35:15Z")

</div>

If you array has elements that are subtypes of `Images.Gray` it get treated as an image automatically.  
Example: [https://docs.juliaplots.org/latest/generated/gr/#gr-ref6-1](https://docs.juliaplots.org/latest/generated/gr/#gr-ref6-1)

---

<div class="post-metadata">

**Author:** ![yha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yha/32/3502_2.png) [@yha](https://discourse.julialang.org/u/yha)\
**Post date:** [May 22, 2020, 11:51pm UTC](https://discourse.julialang.org/t/why-does-plots-jl-require-axis-to-be-in-ascending-order/39926/3 "2020-05-22T23:51:21Z")

</div>

If the array elements are indeed `Gray`s, and you want to just plot a heatmap of their values, rather than showing as an image, you can do

```julia
heatmap(real.(array)) # or gray.(array)

```

(I agree it’s pretty confusing that `heatmap(gray_array)` just shows the image, exactly like `plot(gray_array)`, basically ignoring the plot type)

---

<div class="post-metadata">

**Author:** ![KooshaRaisi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/koosharaisi/32/37513_2.png) [@KooshaRaisi](https://discourse.julialang.org/u/KooshaRaisi)\
**Post date:** [July 5, 2022, 3:24pm UTC](https://discourse.julialang.org/t/why-does-plots-jl-require-axis-to-be-in-ascending-order/39926/4 "2022-07-05T15:24:16Z")

</div>

Hi @fergu !

Unfortunately I also encountered the same weirdness in heatmap.

You can simply say: “yflip = true” within the heatmap parentheses and you should be fine.  
However, if you import your matrix with say, DelimitedFiles.readdlm, and one of your dimensions is imported in reverse, (happened to me as I am cross-checking with MATLAB), you can use:  
ImgArray = reverse(ImgArray, dims = 1) # or 2

Also, if you import your file with readdlm, the
