How to share same legend for different plots?

I have multiple plot!() statements used in a loop. I would like multiple plots to share the same legend, given a label, but Plots generate separate, identical legends for each plot command.

For instance, as a minimal example:

plot([1],[2]; label="A")
plot!([3],[4]; label="A")

I would like both of them to share the same legend, style, etc… Is it possible?

Alternatively, I would like to know how to manually add legends.

I think manually editing legends is tricky in Plots and might require dropping deep into internals.

Could you clarify what the issue is with your first example? For me it creates a plot with just one legend and one label (A), so I’m not sure what you mean by “share the same legend”?

It creates two legends, both of which show the label A. I want one legend with label A.

This arises when I wanted to annotate a plot using some arrows. Multiple arrows share the same category, so they should share the same legend. I have to use multiple plot! command because otherwise only the last line segment has an arrow on it. In addition, arrows are not continuous.

After the first plot that displays the series legend, use for the subsequent plots:

plot!([3],[4]; label=false)
1 Like

OK, I will try that.