# How to add a secondary y-axis (right-side axis) for a waterfall plot in Makie?

**URL:** <https://discourse.julialang.org/t/how-to-add-a-secondary-y-axis-right-side-axis-for-a-waterfall-plot-in-makie/136458>\
**Category:** Visualization\
**Tags:** plotting, makie\
**Created:** [March 30, 2026, 9:35am UTC](https://discourse.julialang.org/t/how-to-add-a-secondary-y-axis-right-side-axis-for-a-waterfall-plot-in-makie/136458 "2026-03-30T09:35:47Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![arafune](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/arafune/32/223622_2.png) [@arafune](https://discourse.julialang.org/u/arafune)\
**Post date:** [March 30, 2026, 9:35am UTC](https://discourse.julialang.org/t/how-to-add-a-secondary-y-axis-right-side-axis-for-a-waterfall-plot-in-makie/136458/1 "2026-03-30T09:35:47Z")

</div>

Hi everyone,

I am trying to create a waterfall plot (stacked line plot) in Makie.jl as shown in the attached image (Fig1.jpg).

I already know how to apply offsets to the lines to create the waterfall effect. However, I am struggling with **how to add a secondary vertical axis on the right side** to represent the “Emission Angle”.

In my case:

- **Left y-axis:** Intensity (with offsets).
- **Right y-axis:** Emission Angle (the parameter that distinguishes each line).

Could anyone point me to the idiomatic way to achieve this in Makie?  
Any code snippets or examples would be very helpful. Thank you!

 ![Fig1](https://global.discourse-cdn.com/julialang/original/3X/5/4/5498e39e4f3593d164b7ce6a80a64575ba1d5f81.png)

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [March 30, 2026, 10:49am UTC](https://discourse.julialang.org/t/how-to-add-a-secondary-y-axis-right-side-axis-for-a-waterfall-plot-in-makie/136458/3 "2026-03-30T10:49:29Z")

</div>

If you’re not actually using the left axis for numeric ticks, just flip the y axis to the right side and use a `Label(fig[i, j, Left()], rotation = pi/2, ...)` for the “Intensity” label.

If you do need a secondary axis, you can currently only achieve that by placing an Axis on top, hiding everything you don’t need and linking the non-twin axis in case you want to plot anything there that needs to be in sync.

---

<div class="post-metadata">

**Author:** ![arafune](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/arafune/32/223622_2.png) [@arafune](https://discourse.julialang.org/u/arafune)\
**Post date:** [March 30, 2026, 11:50am UTC](https://discourse.julialang.org/t/how-to-add-a-secondary-y-axis-right-side-axis-for-a-waterfall-plot-in-makie/136458/4 "2026-03-30T11:50:01Z")

</div>

Thank you for your answer.

I understand. I think there are quite a few situations where a second axis is needed—such as plotting spectrum with energy on the bottom axis and wavelength on the top axis, or plotting reaction rate as a function of the temperature T on the top axis and 1/T on the bottom axis. Thus,I had assumed that Makie would already support this. However, it seems this feature hasn’t been implemented in Makie yet. Is this possible in Plots?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [March 30, 2026, 11:58am UTC](https://discourse.julialang.org/t/how-to-add-a-secondary-y-axis-right-side-axis-for-a-waterfall-plot-in-makie/136458/5 "2026-03-30T11:58:01Z")

</div>

Makie does support it, just like I described above, it’s just not wrapped into another convenience API. If we added one, it would do exactly that I think. If you do this often, you could wrap the couple commands needed into your own function, or think about opening a PR in Makie. I’m not sure if Plots has a keyword for this, probably.

---

<div class="post-metadata">

**Author:** ![arafune](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/arafune/32/223622_2.png) [@arafune](https://discourse.julialang.org/u/arafune)\
**Post date:** [March 30, 2026, 12:08pm UTC](https://discourse.julialang.org/t/how-to-add-a-secondary-y-axis-right-side-axis-for-a-waterfall-plot-in-makie/136458/6 "2026-03-30T12:08:42Z")

</div>

I see, but I’m still having trouble imagining what the actual code/algorithm would look like. Could you show a concrete example?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [March 30, 2026, 2:25pm UTC](https://discourse.julialang.org/t/how-to-add-a-secondary-y-axis-right-side-axis-for-a-waterfall-plot-in-makie/136458/7 "2026-03-30T14:25:21Z")

</div>

You mean like this? [Axis | Makie](https://docs.makie.org/stable/reference/blocks/axis#Creating-a-twin-axis)  
Just the x linking is missing from there, which should be added in case the data does not have exactly the same extent.

---

<div class="post-metadata">

**Author:** ![arafune](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/arafune/32/223622_2.png) [@arafune](https://discourse.julialang.org/u/arafune)\
**Post date:** [March 31, 2026, 1:11am UTC](https://discourse.julialang.org/t/how-to-add-a-secondary-y-axis-right-side-axis-for-a-waterfall-plot-in-makie/136458/8 "2026-03-31T01:11:18Z")

</div>

No,  
In the figure you referred to, the blue sine curve corresponds to the left axis, while the red curve corresponds to the right axis. What I need is a different situation: two vertical axes for a single curve. I would like to know how to link the left and right axes.

In your figure, for example, 1.0 on the left appears to correspond to 100 on the right, and −0.5 to −50. However, in reality, there is no actual relationship between the left and right axes.

What I am looking for is a way to ensure that the two axes are explicitly related through a well-defined transformation, so that each value on the left axis corresponds to a specific value on the right axis.

As I said previously, such situation occurs very frequently (at least in my field, solid state physics). Thus, I had assumed that the plotting library provided the way to do this.

**If anyone knows how to achieve this, I would greatly appreciate your guidance.**

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [March 31, 2026, 8:18am UTC](https://discourse.julialang.org/t/how-to-add-a-secondary-y-axis-right-side-axis-for-a-waterfall-plot-in-makie/136458/9 "2026-03-31T08:18:13Z")

</div>

I think you could do that like this:

```julia
transf(x) = 100 * x - 320

f = Figure()
ax = Axis(f[1, 1])
ax2 = Axis(f[1, 1], yaxisposition = :right, xgridvisible = false)
hidespines!(ax2)

on(ax.finallimits) do lims
    (xmin, ymin), (xmax, ymax) = extrema(lims)
    ymin_trans, ymax_trans = transf.((ymin, ymax))
    limits!(ax2, BBox(xmin, xmax, ymin_trans, ymax_trans))
end

lines!(ax, 0:0.1:10, sin)

f

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/5/d/5d7e07872b35c014c12d73befc7d61832e4f7b68.png)

---

<div class="post-metadata">

**Author:** ![arafune](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/arafune/32/223622_2.png) [@arafune](https://discourse.julialang.org/u/arafune)\
**Post date:** [March 31, 2026, 8:48am UTC](https://discourse.julialang.org/t/how-to-add-a-secondary-y-axis-right-side-axis-for-a-waterfall-plot-in-makie/136458/10 "2026-03-31T08:48:54Z")

</div>

That is wonderful! I found it very informative. Thank you.

---

<div class="post-metadata">

**Author:** ![ederag](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ederag/32/4106_2.png) [@ederag](https://discourse.julialang.org/u/ederag)\
**Post date:** [April 1, 2026, 2:27pm UTC](https://discourse.julialang.org/t/how-to-add-a-secondary-y-axis-right-side-axis-for-a-waterfall-plot-in-makie/136458/11 "2026-04-01T14:27:28Z")

</div>

Here is an alternate take, based on Jule’s answer,  
where the yticks positions are driven by the first axis,  
and the second axis tick labels are simply recalculated.

```julia-auto
# ╔═╡ 4d7d8ae2-ec56-4cdc-bdf7-ffd364f63f4c
using WGLMakie

# ╔═╡ bb240c91-99c6-44cf-88c0-d3952d90a4a0
using Printf

# ╔═╡ be66327a-9bb8-46de-afd3-3570c687de1d
transf(x) = 100 * x - 320

# ╔═╡ ad5b249a-2dd3-11f1-85cb-ab504ea20a19
let
	fig = Figure()
	ax = Axis(fig[1, 1])
	ax2 = Axis(fig[1, 1];
		yaxisposition = :right,
		ygridvisible = false,
		ytickformat = values -> map(values) do value
			@sprintf("%.0f", transf(value))
		end
	)
	hidespines!(ax2)
	hidexdecorations!(ax2)
	
	linkyaxes!(ax, ax2)
	lines!(ax, 0:0.1:10, sin)
	
	fig
end

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/2/3/239509d5fe42e6920ce4243ddf20618b9ee5169c.png)

Pro: there is a single horizontal grid, instead of two intertwined.  
Con: the second axis ticks feel less “natural”.

---

<div class="post-metadata">

**Author:** ![arafune](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/arafune/32/223622_2.png) [@arafune](https://discourse.julialang.org/u/arafune)\
**Post date:** [April 2, 2026, 4:58am UTC](https://discourse.julialang.org/t/how-to-add-a-secondary-y-axis-right-side-axis-for-a-waterfall-plot-in-makie/136458/12 "2026-04-02T04:58:06Z")

</div>

A major drawback is that when the mapping is somewhat complex, such as `transf(x) = 101x - 320`, the values displayed on the right ticks end up being quite non-standard. (Because -1.0 corresponds to -421, and thus, the “-421” is displayed)

In Jule’s way, this issue is overcome. Also, I believe the horizontal grid issue can be resolved by setting `ygridvisible=false`.

Regardless, it was helpful to see that this kind of alternative solution exists.

Thank you.

 ![SS2026-04-02 14.02.47](https://global.discourse-cdn.com/julialang/original/3X/f/7/f7720624d66e448a56d22a6d7519f460ec9978cc.png)
