2012-01-12 80 views

回答

4

可能有办法通过EdgeForm[]FaceForm[]Histogram中摆弄这个,但我发现在我需要的时候单独滚动一个就更简单了。这里是一个非常简单的和简单的例子:

histPlot[data_, bins_, color_: Blue] := Module[{ 
     countBorder = 
    Partition[Riffle[Riffle[#1, #1[[2 ;;]]], Riffle[#2, #2]], 2] & @@ 
    HistogramList[data, bins, "PDF"] 
    }, 
    ListLinePlot[countBorder, PlotStyle -> color] 
    ] 

histPlot[RandomReal[NormalDistribution[],{1000}],{-3,3,0.1}]给出

enter image description here

然后,您可以扩展此采取任何选项,而不是仅仅"PDF",和情况下,当你想自动选择垃圾箱。我不喜欢自动分箱,因为我喜欢控制我的分箱宽度和范围以实现可预测性,并且可以轻松与其他地块进行比较。

+0

谢谢尤达和海克对你有所帮助。尤达,你的独立功能运作良好。 – tos 2012-01-12 21:56:46

5

你也使用ListPlotInterpolationOrder->0

(* example data *) 
data = RandomVariate[NormalDistribution[], 10^3]; 

hist = HistogramList[data, {.5}]; 

ListPlot[Transpose[{hist[[1]], ArrayPad[hist[[2]], {0, 1}, "Fixed"]}], 
    InterpolationOrder -> 0, 
    Joined -> True, 
    AxesOrigin -> {hist[[1, 1]], 0}] 

histogram

+0

@tos对于8岁以上的版本,您可以使用'BinCounts'(需要一些额外的工作) – Szabolcs 2012-01-12 19:01:38

+0

谢谢您的意见。 @Szabolcs,我没有提到我使用的是第8版,但是这个提示对于8版以前的用户来说很方便。 – tos 2012-01-12 21:55:33

1

这里有两种方法,在7版本下工作,使用后处理:

rdat = RandomReal[NormalDistribution[0, 1], 200];
MapAt[ 
    {Blue, 
    Line[# /. {{Rectangle[{x_, y_}, {X_, Y_}]}} :> Sequence[{x, Y}, {X, Y}]] } &, 
    Histogram[rdat, PerformanceGoal -> "Speed"], 
    {1, 2, 2, 2} 
] 

Mathematica graphics

Cases[ 
    Histogram[rdat, PerformanceGoal -> "Speed"], 
    Rectangle[{x_, y_}, {X_, Y_}] :> {{x, Y}, {X, Y}}, 
    \[Infinity] 
]; 

Graphics[Line[Join @@ %], AspectRatio -> 1/GoldenRatio, Axes -> True] 

Mathematica graphics

+0

在升级之前,这与我在v7中使用的非常接近。我不认为这些将在第8版中起作用,因为“直方图”已经发生变化 – abcd 2012-01-13 02:02:58