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

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.

2 Likes

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

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

``````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)

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