# Heatmap(): how do ylim and yflip interact?

**URL:** <https://discourse.julialang.org/t/heatmap-how-do-ylim-and-yflip-interact/134804>\
**Category:** New to Julia\
**Tags:** plotting, bug, plots\
**Created:** [December 30, 2025, 1:43pm UTC](https://discourse.julialang.org/t/heatmap-how-do-ylim-and-yflip-interact/134804 "2025-12-30T13:43:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dankelley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dankelley/32/33539_2.png) [@dankelley](https://discourse.julialang.org/u/dankelley)\
**Post date:** [December 30, 2025, 1:43pm UTC](https://discourse.julialang.org/t/heatmap-how-do-ylim-and-yflip-interact/134804/1 "2025-12-30T13:43:29Z")

</div>

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](https://global.discourse-cdn.com/julialang/original/3X/1/7/179a7be0017132fc6730bf99fa18a3013eba327e.png)  
[heatmap\_question.jl](https://discourse.julialang.org/uploads/short-url/lRo6dwKrqluuA6R2zoMf9uzylTT.jl) (662 Bytes)

---

<div class="post-metadata">

**Author:** ![TimG](https://avatars.discourse-cdn.com/v4/letter/t/82dd89/32.png) [@TimG](https://discourse.julialang.org/u/TimG)\
**Post date:** [December 30, 2025, 2:05pm UTC](https://discourse.julialang.org/t/heatmap-how-do-ylim-and-yflip-interact/134804/2 "2025-12-30T14:05:06Z")

</div>

> [@dankelley](#):
>
> (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.)

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?

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [December 30, 2025, 2:09pm UTC](https://discourse.julialang.org/t/heatmap-how-do-ylim-and-yflip-interact/134804/3 "2025-12-30T14:09:20Z")

</div>

This seems to be a “recent” regression in Plots.jl.  
See [bug report here](https://github.com/JuliaPlots/Plots.jl/issues/4903#issue-2181610762).

For the time being, one possible workaround is:

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

```

---

<div class="post-metadata">

**Author:** ![dankelley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dankelley/32/33539_2.png) [@dankelley](https://discourse.julialang.org/u/dankelley)\
**Post date:** [December 30, 2025, 2:41pm UTC](https://discourse.julialang.org/t/heatmap-how-do-ylim-and-yflip-interact/134804/4 "2025-12-30T14:41:06Z")

</div>

Thanks for the reply. I put the jld2 file at [Dropbox](https://www.dropbox.com/scl/fi/jn1ub7fbihazvq2j288vg/heatmap_question.jld2?rlkey=wkwsx63fbftdkztbolcwh2duh&dl=0)

---

<div class="post-metadata">

**Author:** ![dankelley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dankelley/32/33539_2.png) [@dankelley](https://discourse.julialang.org/u/dankelley)\
**Post date:** [December 30, 2025, 3:24pm UTC](https://discourse.julialang.org/t/heatmap-how-do-ylim-and-yflip-interact/134804/5 "2025-12-30T15:24:54Z")

</div>

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.

 ![section_06_a03](https://global.discourse-cdn.com/julialang/original/3X/b/d/bd827980de1beee25a051d577e87de2fd9ba245e.png)
