How do you label each timeseries on DifferentialEquations.jl plot?

I’ve got the solution to a differential equation, and i want to plot it, and I want each timeseries to have its own label in the legend:

p1 = plot(soln; xlim=(0,0.2), ylim=(0,100), title="Organisms vs Time", xlab="Time / Fly Lifetime",ylab="Organisms / Initial Number Of Adults",legend=:topleft,label=["eggs","larva","pupa","adult","food"])

This leads to the useless legend:

How do I associate names to the timeseries one at a time?

Note that the one example I could find actually just did the above! extremely ugly

https://docs.sciml.ai/SciMLTutorialsOutput/html/introduction/05-formatting_plots.html

Take out the commas between the labels, I think.

Wow, somehow I don’t think I’d have thought of that myself. It’s very odd to require a row matrix of names.

Using a matrix rather than a vector is explained in the Plots.jl documentation below. (I personally don’t like it either.)

Basics · Plots (juliaplots.org)

If the argument is a “matrix-type”, then each column will map to a series, cycling through columns if there are fewer columns than series.

A common error is to pass a Vector when you intend for each item to apply to only one series. Instead of an n-length Vector, pass a 1xn Matrix.

Input Data · Plots (juliaplots.org)

This follows a consistent rule… vectors apply to a series, matrices apply to many series. This rule carries into keyword arguments.

1 Like

I usually build up multi-line plots by doing my own plot! commands one per each, so I guess I managed to avoid needing to figure this out for the last 4 years or so.

It’s kind of amazing how comprehensive the julia Plots.jl infrastructure is.

1 Like