Mathematica中没有垂直线的直方图

时间:2012-01-12 17:56:00

标签: wolfram-mathematica histogram

我正在尝试制作没有垂直线条的直方图。我想要一个看起来像功能的情节。像这样: enter image description here

之前已经问过同样的问题(histogram without vertical lines)但是我在Mathematica上。

我一直在调查ChartStyle选项但没有成功。

3 个答案:

答案 0 :(得分: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

答案 1 :(得分: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",以及您希望自动选择垃圾箱的情况。我不喜欢自动装箱,因为我喜欢控制箱宽和范围以获得可预测性,并且可以轻松地与其他地块进行比较。

答案 2 :(得分: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

相关问题