我正在嘗試製作沒有垂直線的直方圖。我想有一個看起來像一個功能的情節。像這樣: Mathematica中沒有垂直線的直方圖
同樣的問題已被要求R之前(histogram without vertical lines),但我在Mathematica。
我一直在尋找ChartStyle
選項沒有成功。
我正在嘗試製作沒有垂直線的直方圖。我想有一個看起來像一個功能的情節。像這樣: Mathematica中沒有垂直線的直方圖
同樣的問題已被要求R之前(histogram without vertical lines),但我在Mathematica。
我一直在尋找ChartStyle
選項沒有成功。
可能有辦法通過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}]
給出
然後,您可以擴展此採取任何選項,而不是僅僅"PDF"
,和情況下,當你想自動選擇垃圾箱。我不喜歡自動分箱,因爲我喜歡控制我的分箱寬度和範圍以實現可預測性,並且可以輕鬆與其他地塊進行比較。
你也使用ListPlot
與InterpolationOrder->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}]
這裏有兩種方法,在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}
]
Cases[
Histogram[rdat, PerformanceGoal -> "Speed"],
Rectangle[{x_, y_}, {X_, Y_}] :> {{x, Y}, {X, Y}},
\[Infinity]
];
Graphics[Line[Join @@ %], AspectRatio -> 1/GoldenRatio, Axes -> True]
在升級之前,這與我在v7中使用的非常接近。我不認爲這些將在第8版中起作用,因爲「直方圖」已經發生變化 – abcd 2012-01-13 02:02:58
謝謝尤達和海克對你有所幫助。尤達,你的獨立功能運作良好。 – tos 2012-01-12 21:56:46