# Making a plot with related y-axes

**URL:** <https://discourse.julialang.org/t/making-a-plot-with-related-y-axes/2282>\
**Category:** General Usage\
**Created:** [February 24, 2017, 6:03pm UTC](https://discourse.julialang.org/t/making-a-plot-with-related-y-axes/2282 "2017-02-24T18:03:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![thejas.wesley](https://avatars.discourse-cdn.com/v4/letter/t/47e85d/32.png) [@thejas.wesley](https://discourse.julialang.org/u/thejas.wesley)\
**Post date:** [February 24, 2017, 6:03pm UTC](https://discourse.julialang.org/t/making-a-plot-with-related-y-axes/2282/1 "2017-02-24T18:03:23Z")

</div>

Hello!

I’m trying to make a plot (using PyPlot) with two y-axes that are interrelated (one is essentially the inverse of the other). To clarify, I have one set of data, but want the two related y-axes in order to practically use the graph. I was wondering how to best accomplish this.

Thank you!

---

<div class="post-metadata">

**Author:** ![Ralph\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ralph_smith/32/10344_2.png) [@Ralph\_Smith](https://discourse.julialang.org/u/Ralph_Smith)\
**Post date:** [February 25, 2017, 5:54pm UTC](https://discourse.julialang.org/t/making-a-plot-with-related-y-axes/2282/3 "2017-02-25T17:54:14Z")

</div>

In order to force the axes to be in sync (so you can add data, change limits, etc.) you can use “parasite axes”. In principle one can create them with a transform, but it is easier to just tinker with tick locations and labels as follows:

```julia
using PyPlot
using PyCall
const axgr1 = PyNULL()
copy!(axgr1, pyimport("mpl_toolkits.axes_grid1"))

function host_subplot(args...; kwargs...)
    pycall(axgr1["host_subplot"],PyAny, args... ; kwargs...)
end

# make some data
n=100
x=randn(n)
y=exp(x+0.25*rand(n))

# set up figure
f = figure()
ax1 = host_subplot(111)
ax2 = ax1[:twin]() # create parasite axes: defaults to identity transform

# show your data
semilogy(x,y,"o") # just to prove a point

ax1[:set_ylabel]("Custom scale")
ax2[:set_ylabel]("Normal scale")
ax2[:axis]["top"][:toggle](all=false)

# regular plot functions apply to ax1
ytvals = [0.25,0.5,1,2,4,8,16] # usually construct based on extrema(y)
# you can use an arbitrary transformation and format however you like
yticks(ytvals,([string(log2(i)) for i in ytvals]))
ylim(0.05,50)

# default selection isn't very nice
ax2[:set_yticks]([0.1,0.2,0.4,0.8,1,2,4,8,10,20,40])

```

 ![](https://global.discourse-cdn.com/julialang/original/3X/8/7/879e394f4ea89ae1e1330387831b2f61bf9bc057.png)
