Multiple Axis with Plots.jl

Viewed 7956

Is there a way to have the second dataset plot on a separate axis, overlaid on the first plot?

using Plots; gadfly(size=(800,400))

plot(Vector[randn(100)], line = ([:green], :step))

plot!(Vector[randn(100)], line = ([:red], :step))
3 Answers

It is now done by adding a twinx() argument:

plot(rand(10))
plot!(twinx(),100rand(10))

enter image description here

There is, however, some unintentional axis and label behavior:

  1. Labels are plotted on top of each other by default
  2. xticks are plotted on top of the already existing plot
  3. Default colors are not correlated to the total number of series in the subplot

Therefore, I suggest adding some additional arguments:

plot(rand(10),label="left",legend=:topleft)
plot!(twinx(),100rand(10),color=:red,xticks=:none,label="right")

enter image description here

There still seems to be an issue correlating all series associated with the subplot at the moment.

Related