Change ylabel after twinx is generated?

Hey everyone,

I would like to know if it is possible to change only one label name of a simple plot containing a twin axis using Plots. Of course I know that you can do that when calling twinx, but for one of my use, I need to do it AFTER creating the plot.

This is the MWE:

p = plot()
p_twin = twinx(p)

plot!(p, ylabel="sin(x)")

which output this:

As I am only replacing p, I would expect to only change the label of p but that doesn’t seem to be the case…

I would like to be able to only modify the y label on the left.

Okay, I figured it out… I will leave it here in case someone needs it!

p = plot()
p_twin = twinx(p)

plot!(p[1], ylabel="sin(x)")

which gives:

I didn’t understand that twinx was effectively creating another subplot…

1 Like