Heatmap(): how do ylim and yflip interact?

Hello, and happy (almost) New Year.,

First, I’ll apologize for a long-winded question…

I am a longtime R user who is gradually moving to Julia. As an oceanographer, a common task I have is to make image plots of a water property (e.g. temperature) as a function of a horizontal coordinate (e.g. geographic latitude) and depth. We plot such diagrams with depth, a positive number, on the y axis.

Since we want the top of the plot to represent the ocean surface, we want the y axis to decrease upwards, so I assume I ought to use yflip=true in my call to heatmap(). That works fine for me. However, a very common task is to want to limit the view to just say the top 1/4 of the water column, and that is where I get a problem.

Assume ocean depth is 4000 metres. To get the top 1000m, I tried heatmap(..., yflip=true, ylim=(0,1000) but that shows the range from 4000m to 3000m, not the desired range from 1000m to 0m.

I can trick things by using YLIM=ylims() to find the limits of the plot, and then use heatmap(..., ylim=YLIM2].-[1000, 0]) which gives the correct image, but of course then the axes are wrong.

I am using the GR plotting scheme in Julia version 1.12.3 on a mac running Tahoe 26.3.

I wonder whether this is something that is familiar to other users, with a simple fix.

I’m uploading sample code and results, in case that helps. (I cannot see how to upload the .jld2 file, though, and creating that file requires a reader to install software, download oceanographic data files, etc.)

In the image I’ve attached, the top panel is the full-depth view of ocean salinity, with lines drawn 1000m below the surface and 1000m above the deepest point. The middle panel is what I had hoped would work, but inspection with respect to the top panel indicates that it is actually showing the bottom 1000m. The bottom panel is what I get by fiddling ylim, which gives me the view I want (again, see the lines in the top panel) but of course the y axis is wrong. I could fake things by not drawing that axis, but I want to be able to later add annotations to the diagram, so proper values of y are important to me.

I’m sorry for the length of this question.


heatmap_question.jl (662 Bytes)

Could you put the file on some cloud-based file sharing service (One Drive, Google Drive, DropBox, GitHub - there are many others) and share a link to it from there?

This seems to be a “recent” regression in Plots.jl.
See bug report here.

For the time being, one possible workaround is:

ix = @. 3000 ≤ z ≤ 4000
heatmap(x, z[ix], T'[ix,:], yflip=true)

Thanks for the reply. I put the jld2 file at Dropbox

I used that subset trick you mentioned, and of course it works well. In case it’s of any interest, below is what my code does now. The top shows the locations of data, off the eastern coast of the USA.

Thanks again for the quick and insightful advice, and for letting me know that there is a bug in the julia-plot system. I’ll make my code check for the julia version, so if it gets fixed then my code won’t need to do this subsetting.

1 Like