Methods for Coloring Up to a Certain Value from Curves in Julia / Between Two Curves / Inside a Closed Curve
Fill up to a Specific Value1
Using attributes fillrange=a
, fillalpha=b
, fillcolor=:color
in plot()
, it colors with :color
to the value a
from the plotted curve with the transparency b
. It works the same by writing fill=(a,b,:color)
. That is, the following two codes are the same.
plot(x,y, fillrange=a, fillalpha=b, fillcolor=:color)
plot(x,y, fill=(a,b,:color))
It seems to be a bug, but selecting the value of fillrange
as $(0,1)$ does not get colored.
using Plots
random_walk = cumsum(rand(20).-.5)
p1 = plot(random_walk,fill=(1,0.2,:lime), lw=3, legend=:bottomright)
p2 = plot(random_walk,fill=(2,0.2,:tomato), lw=3, legend=:bottomright)
plot(p1, p2)
Filling Between Two Curves
By putting one of the curve’s function values into fillalpha
, the area between two curves gets colored.
rw = random_walk
plot([rw rw.+1],fill=(rw.+1,0.2,:lime), lw=3, legend=:bottomright)
Filling Inside a Closed Curve
The inside gets colored if fillalpha
’s value is chosen not only from $(0,1)$.
theta = range(0,2pi, length=40)
x = cos.(theta)
y = sin.(theta)
plot(x, y, fill=(1,0.2,:lime), xlim=(-3,3), ylim=(-1.5,1.5), size=(800,400), lw=3)
Environment
- OS: Windows10
- Version: Julia 1.6.2, Plots 1.23.6