user4651282
user4651282

Reputation:

How fill area under each line separately with Plots.jl?

I tried fill area under each line separately with Plots.jl. Here my code:

using Plots;
gr()
Data = Tuple{Float64,Float64}[]
p=plot([0.1,1.0],[1,1],fill=(0,:green))
push!(p,[1.6,1.8],[1,1])
push!(p,[2.2,2.5],[1,1])
push!(p,[3.2,3.5],[1,1])

but this not work:

result

How make this correctly if it possibly?

Upvotes: 2

Views: 1501

Answers (1)

Tasos Papastylianou
Tasos Papastylianou

Reputation: 22245

It's not clear what you want, but I think you're trying to cover rectangular areas. Here is one way to do it:

p=plot([0.1, 1.0], [1, 1],fill=(0,:green))
append!(p, 1, [1.0,1.6,1.6,1.8], [0,0,1,1])
append!(p, 1, [1.8,2.2,2.2,2.5], [0,0,1,1])
append!(p, 1, [2.5,3.2,3.2,3.5], [0,0,1,1])

Note that you need to specify the "zero areas" too, otherwise the area graph will join over the "data gap" resulting in an uninterrupted green area. (equally if you only append single points instead of "zero" and "one" segments, you'll get a linear rise instead of a steep rise).

enter image description here

Upvotes: 1

Related Questions