How to Plot Two Data Axes of Different Scales in Julia Plots
Code
When plotting two data sets that have a large scale difference on the same plot, the one with the smaller scale gets completely ignored as shown in the figure below.
using Plots
x = 0:0.01:2π
plot(x, sin.(x))
plot!(x, exp.(x))
When plotting the second data set, if you input twinx()
as the first argument, it shares the $x$ axis and the graph is drawn on the new $y$ axis.
plot(x, sin.(x), ylabel = "sin x")
plot!(twinx(), x, exp.(x), ylabel = "exp x")
Conversely, to share the $y$ axis and plot, you can input twiny()
as the first argument.
Environment
- OS: Windows11
- Version: Julia 1.9.4, Plots v1.39.0