我可以在单个情节中指定不同的填充颜色,如下图或我需要“显示”几个情节吗?让我们说我希望填充样式与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}]
答案 0 :(得分:13)
您需要使用FillingStyle
来填写。我认为您遇到了FillingStyle
的语法,其与<{em>的语法相同<{1}} 1}},虽然你期望它是。您必须为每条曲线指定一种颜色PlotStyle
,等等。以下是一个示例:
FillingStyle -> {1 -> color1, 2 -> color2}
答案 1 :(得分:9)
我建议对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"
有了这个,您可以使用FillingStyle -> "Match"
自动设置填充样式以匹配主要样式。
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"
]
答案 2 :(得分:8)
您可以执行类似
的操作With[{colours = {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 ->
MapIndexed[#2[[1]] -> {Axis, Directive[Opacity[.3, #1]]} &, colours],
PlotStyle -> colours]]
答案 3 :(得分:3)
这会得到一个结果:
Plot[Evaluate@
MapThread[
Function[{\[Mu], \[Sigma]},
PDF[NormalDistribution[\[Mu], Sqrt[\[Sigma]]], x]], {{priorMean,
llhMean, postMean}, {priorVar, llhVar, postVar}}], {x, 0, 100},
Filling -> {1 -> {Axis, Red}, 2 -> {Axis, Green}, 3 -> {Axis, Blue}},
PlotStyle -> {Red, Green, Blue}]
在FillingStyle,Scope,Filling Style下的帮助中找到。
另外:
f = MapThread[
Function[{\[Mu], \[Sigma]},
PDF[NormalDistribution[\[Mu], Sqrt[\[Sigma]]], x]],
{{priorMean, llhMean, postMean}, {priorVar, llhVar, postVar}}];
c = {Red, Green, Blue};
Show[Array[
Plot[f[[#]], {x, 0, 100}, Filling -> {1 -> {Axis, c[[#]]}},
PlotRange -> {Automatic, 0.08}, PlotStyle -> c[[#]]] &, 3]]