Reputation: 14077
Let's say my altitude-pressure function is:
P(h) = p0 * exp(-h/scale)
I'd want to draw a set of plots for different planets; the same graph (canvas) but different p0
and scale
parameters, a pair (plus name of the planet) per one planet.
Do I have to enter "multiplot" and reassign scale =
and p0 =
before calling the same plot P(h)
for every set of parameters or is there a neater way to get a set of graphs like this?
Upvotes: 2
Views: 57
Reputation: 48440
You can define three different space-separated string which hold the parameters and then iterate over them:
p0 = "1 2 3 4"
scale = "0.1 0.2 0.3 0.4"
planets = "First Second Third Fourth"
P(h, n) = (1.0*word(p0, n)) * exp(-h/(1.0*word(scale, n)))
plot for [i=1:words(planets)] P(x, i) title word(planets, i)
The 1.0*
is used to 'convert' the respective string to a number. Ugly, but works. If you want it a bit cleaner, you could define functions p0
and scale
to return a number depending on an iteration parameter
p0(n) = (n==1 ? 1 : n==2 ? 2 : n==3 ? 3 : 4)
scale(n) = (n==1 ? 0.1 : n==2 ? 0.2 : n==3 ? 0.3 : 0.4)
P(h, n) = p0(n)*exp(-h/scale(n))
plot for [i=1:words(planets)] P(x, i) title word(planets, i)
Upvotes: 2