我正在尝试使用mathematica中的移动平均来平滑3D直方图。我知道有一个名为smoothhistogram3D的函数,它接近我想要的,但是,它似乎只能选择使用分布函数来平滑曲线。通过修改this stackoverflow answer以包含interpolationOrder和移动平均特征,我能够创建一个平滑2D直方图的函数。
MovAvgHistoPlot[MovAvg_, dx_] := Module[{histList, transposedHistList, histListAvg},
histList = HistogramList[data, {dx}];
transposedHistList = Transpose[{histList[[1]],ArrayPad[histList[[2]], {0, 1},
"Fixed"]}];
histListAvg = MovingAverage[transposedHistList, MovAvg];
histPlot = ListPlot[histListAvg, InterpolationOrder -> 3, Joined -> True,
AxesOrigin -> {histListAvg[[1, 1]], 0}, PlotRange -> All, InterpolationOrder -> 3,
PlotStyle -> Black, FrameLabel -> {"kTh", "Ion Intensity"},Frame -> {{True, False},
{True, False}}, Axes -> False, ImageSize -> Large]
]
Manipulate[MovAvgHistoPlot[MovAvg, dx], {{MovAvg, 1, "Moving Average"}, 1, 500, 1},
ContinuousAction -> False]
我尝试使用下面的代码将其扩展到第三维,但没有成功。
MovAvgHistPlot3D[MovAvg_] := Module[{HistList3D, XAndZGroupedValues, XValues, ZValues,
XAndZValues, YValues, ListPlot3DPoints},
HistList3D = HistogramList[data];
XAndZValues = Flatten[Partition[Table[Riffle[HistList3D[[1, 2]],
HistList3D[[1, 1, i]], {1, -1, 2}], {i,Length[HistList3D[[1, 1]]]}], {1, 2}]];
YValues = Flatten[ArrayPad[Map[ArrayPad[##, {0, 1}, "Fixed"] &, HistList3D[[2]]],
{0, 1}, "Fixed"]];
ListPlot3DPoints = Partition[Riffle[XAndZValues, YValues, {3, -1, 3}], 3];
ListPlot3DPointsAvg = MovingAverage[ListPlot3DPoints, MovAvg];
ListPlot3D[ListPlot3DPointsAvg, InterpolationOrder -> 3, Joined -> True]
]
Manipulate[MovAvgHistPlot3D[MovAvg], {{MovAvg, 1, "Moving Average"}, 1, 1000, 1},
ContinuousAction -> False]
但是,3D功能使用我的数据集输出此图像:http://imgur.com/MJeBbwW
我尝试使用与此类似的方法,除了可以选择使用移动平均线来平滑它:
ListPlot3D[HistogramList[filteredData1]]
然而,它输出了这样的图像:
http://imgur.com/Bkj0R9W
(Sorry, can't post more than two links due to lack of reputation points)
我想要的数据集与smoothhistogram3D的输出非常相似,但可以选择平滑移动平均线。
http://imgur.com/NRj6V2R
有什么建议吗?有没有更简单的方法我没有意识到?
很抱歉,我意识到代码,尤其是第二部分,几乎无法读取。我是mathematica的新手,只是想让它发挥作用。
这也是我第一次发布堆栈溢出,请原谅任何格式或指南错误。