Could I specify different filling colors for within a single plot like the bellow or would I need to "Show" several Plots ? Let`s say I would like the filling style to be the same as the PlotStyle.
priorMean = 50;
priorVar = 100;
llhMean = 30;
llhVar = 40;
postMean=35.71;
postVar=28.57;
Plot[
Evaluate@MapThread[
Function[{\[Mu], \[Sigma]},
PDF[NormalDistribution[\[Mu], Sqrt[\[Sigma]]], x]],
{{priorMean, llhMean, postMean}, {priorVar, llhVar, postVar}}],
{x, 0, 100}, Filling -> Axis, PlotStyle -> {Red, Green, Blue}]
is an option for plotting and related functions that specifies styles in which objects are to be drawn.
You'll need to use FillingStyle
to fill in. I think you got stuck in the syntax for FillingStyle
, which is not the same as that for PlotStyle
, although you'd expect it to be. You'll have to assign a color for each curve as FillingStyle -> {1 -> color1, 2 -> color2}
, etc. Here's an example:
colors = {Red, Green, Blue};
Plot[Evaluate@
MapThread[
Function[{\[Mu], \[Sigma]},
PDF[NormalDistribution[\[Mu], Sqrt[\[Sigma]]], x]], {{priorMean,
llhMean, postMean}, {priorVar, llhVar, postVar}}], {x, 0, 100},
Filling -> Axis, PlotStyle -> colors,
FillingStyle ->
MapIndexed[#2 -> Directive[Opacity[0.3], #] &, colors]]
I propose making an extension to the definition of Plot
. I have done this before.
toDirective[{ps__} | ps__] := Flatten[Directive @@ Flatten[{#}]] & /@ {ps}
makefills = MapIndexed[#2 -> Join @@ toDirective@{Opacity[0.3], #} &, #] &;
Unprotect[Plot];
Plot[a__, b : OptionsPattern[]] :=
Block[{$FSmatch = True},
With[{fills = makefills@OptionValue[PlotStyle]},
Plot[a, FillingStyle -> fills, b]
]] /; ! TrueQ[$FSmatch] /; OptionValue[FillingStyle] === "Match"
With this in place, you can use FillingStyle -> "Match"
to auto-style the fills to match the main styles.
Plot[{Sin[x], Cos[x], Log[x]}, {x, 0, 2 Pi},
PlotRange -> {-2, 2},
PlotStyle -> {{Blue, Dashing[{0.04, 0.01}]},
{Thick, Dashed, Orange},
{Darker@Green, Thick}},
Filling -> Axis,
FillingStyle -> "Match"
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With