Multiple Axes in Julia
How to make a graph with multiple axes (dual y-axis plots, plots with secondary axes) in julia.
Plotly is known for its graphing libraries, but it's also a broader ecosystem for building interactive data apps, AI data analysis tools, and deploying and hosting Dash apps. Explore the full set of tools and platforms designed to help turn data into action. Discover Plotly.
Note: We are retiring documentation for R, MATLAB, Julia, and F#. Learn more about this change here.
Two Y Axes
using PlotlyJS
plot(
[
scatter(x=1:3, y=40:10:60, name="yaxis data"),
scatter(x=2:4, y=4:6, name="yaxis2 data", yaxis="y2")
],
Layout(
title_text="Double Y Axis Example",
xaxis_title_text="xaxis title",
yaxis_title_text="yaxis title",
yaxis2=attr(
title="yaxis2 title",
overlaying="y",
side="right"
)
)
)
Multiple Axes
Low-level API for creating a figure with multiple axes
using PlotlyJS
traces = GenericTrace[]
for i in 1:4
trace = scatter(x=(i+1):(i+3), y=4:6 .* (10^i), yaxis="y$i", name="yaxis$i data")
push!(traces, trace)
end
plot(
traces,
Layout(
xaxis_domain=[0.3, 0.7],
yaxis=attr(title="yaxis title", titlefont_color="red"),
yaxis2=attr(
title="yaxis2 title", titlefont_color="blue",
overlaying="y", side="left", position=0.15, anchor="free"
),
yaxis3=attr(
title="yaxis3 title", titlefont_color="green",
overlaying="y", side="right", anchor="x",
),
yaxis4=attr(
title="yaxis4 title", titlefont_color="orange",
overlaying="y", side="right", position=0.85, anchor="free",
),
title_text="multiple y-axes example",
)
)
Reference
All of the y-axis properties are found here: https://plotly.com/julia/reference/YAxis/. For more information on creating subplots see the Subplots in Julia section.