MathTop

histogram 函数

根据数值样本绘制直方图。

语法

  • histogram([v1, v2, ...])
  • histogram(values, bins = n, option = value, ...)

参数与选项

list形如 [1, 2, 3] 的列表字面量。
bins直方图分箱数量。
title图形上方显示的标题文本。
labels坐标轴或类别标签。2D 图通常为 [xLabel, yLabel];图表中在支持时用于标注分类。
color / colour颜色名、CSS 颜色,或用于多个系列/图元的颜色列表。
axes坐标轴显示控制;使用 none/false 隐藏坐标轴。
gridlines网格线显示控制;true 显示,false 隐藏。
background图形背景颜色。
transparency透明度控制,范围 0 到 1,数值越大越透明。
view可见数值范围,例如 [xmin..xmax, ymin..ymax] 或 [xmin..xmax, ymin..ymax, zmin..zmax]。

示例

  1. 直方图histogram([1, 1, 2, 2, 2, 3, 4], bins = 4)样本分入四个直方图区间。
  2. 分箱histogram([1, 1, 2, 2, 2, 3, 4], bins = 3)样本分入三个区间。
  3. 标题histogram([1, 1, 2, 2, 2, 3, 4], bins = 4, title = 'Distribution')直方图显示指定标题。
  4. 颜色histogram([1, 1, 2, 2, 2, 3, 4], bins = 4, color = cyan)直方条绘制为青色。
  5. 坐标轴与网格histogram([1, 1, 2, 2, 2, 3, 4], bins = 4, axes = none, gridlines = false)直方图结果包含指定的坐标轴和网格选项。
  6. 背景histogram([1, 1, 2, 2, 2, 3, 4], bins = 4, background = '#f8fafc')直方图使用自定义背景。
  7. 透明度histogram([1, 1, 2, 2, 2, 3, 4], bins = 4, transparency = 0.25)直方条以半透明方式绘制。
  8. 显示范围histogram([1, 1, 2, 2, 2, 3, 4], bins = 4, view = [0..5, 0..4])固定可见的直方图窗口。
  9. 综合选项histogram([1, 1, 2, 2, 2, 3, 4], bins = 4, title = 'Distribution', color = cyan, background = '#f8fafc', transparency = 0.2, view = [0..5, 0..4])同时应用分箱数、标题、颜色、背景、透明度和显示范围。