# Issues with secondary y-axis in Plots.jl

**URL:** <https://discourse.julialang.org/t/issues-with-secondary-y-axis-in-plots-jl/109107>\
**Category:** Visualization\
**Tags:** plots\
**Created:** [January 22, 2024, 4:08pm UTC](https://discourse.julialang.org/t/issues-with-secondary-y-axis-in-plots-jl/109107 "2024-01-22T16:08:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aleppersico](https://avatars.discourse-cdn.com/v4/letter/a/51bf81/32.png) [@aleppersico](https://discourse.julialang.org/u/aleppersico)\
**Post date:** [January 22, 2024, 4:08pm UTC](https://discourse.julialang.org/t/issues-with-secondary-y-axis-in-plots-jl/109107/1 "2024-01-22T16:08:25Z")

</div>

Hello all, 🙂

I am working on a plot with two y-axis. The plot is showing how a quantity is changing over time and I would like to have on the left axis its nominal value and on the right axis the percentage variation.

Now, with these simple lines I am able to produce the desired plot:

```julia
ttime = 0:10
nominal = exp.(-ttime/2)
percentace = 100*(nominal .- nominal[1])/nominal[1]
plot(ttime, nominal,lw=2,label="nominal")
plot!(gridalpha=0.3)
xlabel!("Time")
ylabel!("Nominal")
axis2 = twinx()
ylims!(axis2,100*(ylims()[1]-nominal[1])/nominal[1],100*(ylims()[2]-nominal[1])/nominal[1])
ylabel!(axis2,"Percentage")

```

However, the final plot misses any horizontal grid while I would like to keep it with the reference of the left y-axis values:

 ![Julia question](https://global.discourse-cdn.com/julialang/original/3X/7/c/7c9f5534efd49991d4cb732174a76a93e41a42e7.png)

Can anybody help here? 😀

---

<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:** [January 22, 2024, 6:40pm UTC](https://discourse.julialang.org/t/issues-with-secondary-y-axis-in-plots-jl/109107/2 "2024-01-22T18:40:27Z")

</div>

Assign the left y-axis plot to `axis1` and then add ` plot!(axis1, grid=true)` as the last line in your code snippet.

> **edited code**
>
> ```julia
> using Plots; gr(dpi=600)
> 
> ttime = 0:10
> nominal = exp.(-ttime/2)
> percentace = 100*(nominal .- nominal[1])/nominal[1]
> axis1 = plot(ttime, nominal,lw=2,label="nominal")
> plot!(gridalpha=0.3)
> xlabel!("Time")
> ylabel!("Nominal")
> axis2 = twinx()
> # plot!(grid=:on)
> ylims!(axis2, 100*(ylims()[1]-nominal[1])/nominal[1], 100*(ylims()[2]-nominal[1])/nominal[1])
> ylabel!(axis2, "Percentage")
> plot!(axis1, grid=true)
> 
> ```
