Can I make a plot with gradient filling?
How about this?
bankerPlot[data_] := ListLinePlot[
data,
AxesOrigin -> {0, 0},
Prolog -> Polygon[Join[data, Reverse[data.DiagonalMatrix[{1, 0}]]],
VertexColors -> Join[
Blend[{Black, Blue}, #] & /@ Normalize[data[[All, 2]], Max],
ConstantArray[Black, Length[data]]
]
],
PlotStyle -> White,
Background -> Black,
AxesStyle -> White
]
bankerData = Transpose[{Range[100], Accumulate[RandomReal[{-1, 1}, 100]] + 10}];
bankerPlot[bankerData]
For plotting a continuous function, you could do something like this:
f[x_] := (1 + Cos[5 x]/2) Sin[x]
ParametricPlot[{x, f[x] y}, {x, 0, Pi}, {y, 0, 1},
PlotPoints -> 30,
ColorFunction -> (Blend[{Black, Blue, White}, #2] &), Mesh -> None,
AspectRatio -> 1/GoldenRatio]
Edit
This method can be used for plotting a list of points as well by interpolating the points first, e.g.
pts1 = RandomReal[10, 100];
interpol = Interpolation[pts1, InterpolationOrder -> 1];
ParametricPlot[{x, interpol[x] y}, {x, 1, Length[pts1]}, {y, 0, 1},
ColorFunction -> (Blend[{Black, Blue, White}, #2] &), Mesh -> None,
AspectRatio -> 1/GoldenRatio]
Here's a modification of Heike's ParametricPlot
approach, using textures instead of ColorFunction
.
pts1 = RandomReal[10, 100];
interpol = Interpolation[pts1, InterpolationOrder -> 1];
ParametricPlot[{u, interpol[u] v}, {u, 1, Length[pts1]}, {v, 0, 1},
Mesh -> None, AspectRatio -> 1/GoldenRatio,
TextureCoordinateFunction -> ({#1, #2} &),
PlotStyle -> {Opacity[1],
Texture[Table[{{##}} & @@ Blend[{Black, Blue, White}, 1-i],
{i, 0, 1, 0.01}]]}]
I'm using a 1-pixel wide Image
containing the black-blue-white gradient Heike used. (Actually, it doesn't have an Image
head; it's just the ImageData
.)
I'm also specifying that I want the texture to correspond to the $x$ and $y$ coordinates instead of the default of $u$ and $v$.
This approach allows us to generalize the gradient to something more complicated, or even an arbitrary image:
ParametricPlot[{u, interpol[u] v}, {u, 1, Length[pts1]}, {v, 0, 1},
Mesh -> None, AspectRatio -> 1/GoldenRatio,
TextureCoordinateFunction -> ({#1, #2} &),
PlotStyle -> {Opacity[1], Texture[ExampleData[{"TestImage", "Lena"}]]}]