画普通的统计分布填充图


最直接简单的思路是,多条曲线,只填充其中需要填充的:

With[{dist := PDF[NormalDistribution[]]}, 
 Plot[{dist[x], If[x < 1 && x > -2, dist[x]]}, {x, -5, 5}, 
  Filling -> {2 -> {Axis, Directive[Opacity[0.45], Blue]}}, 
  AspectRatio -> .85/GoldenRatio, PlotStyle -> Blue, 
  AxesOrigin -> {0, 0}]]


但是这样搞分段函数,调整区间的情况下不是很方便; 利用参数方程绘图的区块绘制功能则方便

With[{pdf = PDF[NormalDistribution[]], cv = 1}, 
 ParametricPlot[{x, t pdf[x]}, {x, -5, 5}, {t, 0, 1}, 
  MeshFunctions -> {#3 &}, Mesh -> {{-cv}}, 
  MeshShading -> {Directive[Opacity[0.42], ColorData[2][6]], None}, 
  AspectRatio -> 1/GoldenRatio, PlotRange -> All, Frame -> False]]

看个复杂点的效果,也是一口气完成:

With[{pdf = PDF[NormalDistribution[]], cv = 2}, 
 ParametricPlot[{x, t pdf[x]}, {x, -5, 5}, {t, 0, 1}, 
  MeshFunctions -> {#3 &}, Mesh -> {{-cv, 0, 1, 2, 3}}, 
  MeshShading -> {None, Directive[Opacity[0.42], ColorData[1][2]]}, 
  AspectRatio -> 1/GoldenRatio, PlotRange -> All, Frame -> False]]

对比下面的区别:

With[{pdf = PDF[NormalDistribution[]], cv = 2}, 
 ParametricPlot[{x, t pdf[x]}, {x, -5, 5}, {t, 0, 1}, 
  MeshFunctions -> {#3 &}, Mesh -> {{-cv, cv}}, 
  MeshShading -> {None, Directive[Opacity[0.42], ColorData[1][2]]}, 
  AspectRatio -> 1/GoldenRatio, PlotRange -> All, Frame -> False]]


With[{pdf = PDF[NormalDistribution[]], cv = 2}, 
 ParametricPlot[{x, t pdf[x]}, {x, -5, 5}, {t, 0, 1}, 
  MeshFunctions -> {#3 &}, Mesh -> {{-cv, cv}}, 
  MeshShading -> {Directive[Opacity[0.42], ColorData[1][2]], None}, 
  AspectRatio -> 1/GoldenRatio, PlotRange -> All, Frame -> False]]

ParametricPlot[
 r^2 { Sqrt[t] Cos[t], 3 Sin[t]}, {t, 0, 6 Pi}, {r, 1.8, 2}, 
 MeshFunctions -> {#3 &}, Mesh -> {Range[1, 100]/5}, 
 MeshShading -> {None, Directive[Opacity[0.42], ColorData[1][2]]}, 
 Axes -> False, Frame -> False]


ParametricPlot[{u {-Sin[t], Cos[t]}, u {Sin[t], Cos[t]}}, {t, 0, 
  Pi}, {u, 0, 1},
 MeshFunctions -> {(Boole[(
       If[#1 <= 0,
        #2 - Sqrt[0.25 - (#1 + 0.5)^2] >= 0 || (#1 + .5)^2 + #2^2 < 
          1/64,
        #2 + Sqrt[0.25 - (#1 - 0.5)^2] >= 0 && (#1 - .5)^2 + #2^2 > 
          1/64]
       )] &)}, Mesh -> {{0.1}}, MeshShading -> {Blue, Red}, 
 PlotPoints -> 70,
 Frame -> False, Axes -> False, BoundaryStyle -> None, 
 ImageSize -> Large]


参考:

http://mathematica.stackexchange.com/questions/37103/plotting-confidence-intervals

http://mathematica.stackexchange.com/questions/25169/how-to-plot-filling-under-a-curve/25216#25216

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值