3
$\begingroup$

I try to plot some data in Mathematica using the ListLinePlot[]. Unfortunately the plot option ColorFunction, Filling and FillingStyle won't work together. For example:

ListLinePlot[data1D,
  ColorFunction -> "Rainbow",
  ColorFunctionScaling -> True,
  PlotStyle -> Thick,
  Filling -> Axis
] 

will give me the following result:

ListLinePlot w.o. Opacity

The issue with this plot is the missing opacity. You can barely see the axes label and it gets worse when you use multiple functions. The FillingStyle option gives theoretically the possibility to change the opacity. Adding the following line to my code

FillingStyle -> Opacity[0.1]

gives me some opacity but unfortunately I lose the ColorFunction:

ListLinePlot with Opacity

Does somebody have any idea how to use Filling, FillingStyle, Opacity and ColorFunction together?

Thanks a lot!

$\endgroup$
6
$\begingroup$

To get both the Opacity and the mapping of the colour to the function value not the x-coordinate, try this:

ListLinePlot[data1D, PlotStyle -> {Opacity[0.4]}, Filling -> Axis, 
 ColorFunction -> 
  Function[{horiz, vert}, Opacity[.7, ColorData["Rainbow"][vert]]]]

The trick is to make the pure function have two arguments, but only use the second.

enter image description here

$\endgroup$
  • $\begingroup$ works perfectly! Thanks a lot! $\endgroup$ – Tommy Sep 28 '15 at 0:22
3
$\begingroup$

The problem is that you have to add the opacity to the colorfunction or you get some kind of an error in your color function and it turns to a grey colored blank.

ListLinePlot[data1D, PlotStyle -> {Opacity[0.4]}, Filling -> Axis, 
ColorFunction -> Function[f, Opacity[.7, ColorData["Rainbow"][f]]]]

note you can remove that Plotstyle.

ListLinePlot[data1D, Filling -> Axis, 
ColorFunction -> Function[f, Opacity[.5, ColorData["Rainbow"][f]]]]

enter image description here

Edit:

As Verbeia mentioned all the possibilities with colorfunction are viable, and you can set to colorfunction to change with respect the vertical axes.

ListLinePlot[data1D, Filling -> Axis, 
ColorFunction -> 
Function[{x, y}, Opacity[.5, ColorData["Rainbow"][y]]]
]

enter image description here

$\endgroup$
  • $\begingroup$ This is good but doesn't quite replicate what he is looking for, which maps the colour value to the function value, not the x-coordinate. $\endgroup$ – Verbeia Sep 27 '15 at 23:22
  • $\begingroup$ yes, you are right, I was mentioning the issue forgot the vertical part. $\endgroup$ – Raymond Ghaffarian Shirazi Sep 27 '15 at 23:42
2
$\begingroup$

BaseStyle

data1 = Accumulate[RandomReal[{-1, 1}, 250]];
ListLinePlot[data1, ColorFunction -> "Rainbow", PlotStyle -> Thick, 
 Filling -> Axis, BaseStyle -> FaceForm[Opacity[.3]]]

enter image description here

Post-processing

ListLinePlot[data1, ColorFunction -> "Rainbow", PlotStyle -> Thick, Filling -> Axis] /.
 p_Polygon :> {Opacity[.3], p}

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.