2012-01-12 78 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