使用Mathematica中的单个绘图填充样式

500*_*500 11 plot wolfram-mathematica

我可以在一个单独的情节中指定不同的填充颜色,如下图或我需要"显示"几个情节吗?让我们说我希望填充样式与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}]
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

abc*_*bcd 13

你需要用来FillingStyle填写.我认为你的语法卡住了FillingStyle,这与你的语法一样PlotStyle,尽管你期望它.你必须为每条曲线分配一种颜色FillingStyle -> {1 -> color1, 2 -> color2},等等.这是一个例子:

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]]
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


Mr.*_*ard 9

我建议对...的定义进行扩展Plot. 我之前做过这个.

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"
Run Code Online (Sandbox Code Playgroud)

有了这个,您可以使用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"
]
Run Code Online (Sandbox Code Playgroud)

Mathematica图形


Hei*_*ike 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]]
Run Code Online (Sandbox Code Playgroud)

填充不同的颜色