Skip to content

Commit bd153dd

Browse files
committed
add legend to step plot
1 parent 3d41fbc commit bd153dd

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/ControlSystemsBase/ext/ControlSystemsBaseMakieExt.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,10 @@ function Makie.plot!(fig, r::SimResult; plotu=false, plotx=false, ploty=true)
631631
stairs!(ax, t, r.y[i, :, ms], label=label, step=:post)
632632
end
633633
end
634+
# Add legend if there are multiple series
635+
if n_series > 1
636+
axislegend(ax, position=:rt)
637+
end
634638
plotind += 1
635639
end
636640
end
@@ -662,12 +666,14 @@ function Makie.plot!(fig, r::SimResult; plotu=false, plotx=false, ploty=true)
662666

663667
if n_series > 1
664668
for ms in 1:n_series
669+
label = "From $(input_names(r.sys)[ms])"
665670
if iscontinuous(r.sys)
666-
lines!(ax, t, r.x[i, :, ms])
671+
lines!(ax, t, r.x[i, :, ms], label=label)
667672
else
668-
stairs!(ax, t, r.x[i, :, ms], step=:post)
673+
stairs!(ax, t, r.x[i, :, ms], label=label, step=:post)
669674
end
670675
end
676+
axislegend(ax, position=:rt)
671677
else
672678
if iscontinuous(r.sys)
673679
lines!(ax, t, r.x[i, :])

0 commit comments

Comments
 (0)