maxframe.dataframe.Series.plot.bar#

Series.plot.bar(*args, **kwargs)#

垂直条形图。

条形图是一种用矩形条表示分类数据的图形,其长度与所表示的数值成比例。条形图展示了离散类别之间的比较。图形的一个轴显示被比较的具体类别,另一个轴表示测量值。

参数:
  • x (label or position, optional) -- 允许绘制一列相对于另一列的图。如果未指定,则使用 DataFrame 的索引。

  • y (label or position, optional) -- 允许绘制一列相对于另一列的图。如果未指定,则使用所有数值列。

  • color (str, array-like, or dict, optional) --

    DataFrame 每一列的颜色。可能的值有:

    • A single color string referred to by name, RGB or RGBA code, for instance 'red' or '#a98d19'.

    • A sequence of color strings referred to by name, RGB or RGBA code, which will be used for each column recursively. For instance ['green','yellow'] each column's bar will be filled in green or yellow, alternatively. If there is only a single column to be plotted, then only the first color from the color list will be used.

    • A dict of the form {column name : color}, so that each column will be colored accordingly. For example, if your columns are called a and b, then passing {'a': 'green', 'b': 'red'} will color bars for column a in green and bars for column b in red.

  • **kwargs -- 其他关键字参数在 DataFrame.plot() 中有说明。

返回:

subplots=True 时,返回一个 ndarray,每个列对应一个 matplotlib.axes.Axes

返回类型:

matplotlib.axes.Axes or np.ndarray of them

参见

DataFrame.plot.barh

Horizontal bar plot.

DataFrame.plot

Make plots of a DataFrame.

matplotlib.pyplot.bar

Make a bar plot with matplotlib.

示例

基本绘图。

(Source code)

将整个 DataFrame 绘制为条形图。每一列被分配一个不同的颜色,每一行沿着水平轴嵌套在一个组中。

(Source code)

绘制 DataFrame 的堆叠条形图

(Source code)

Instead of nesting, the figure can be split by column with subplots=True. In this case, a numpy.ndarray of matplotlib.axes.Axes are returned.

(Source code)

如果您不喜欢默认颜色,您可以指定每列的颜色。

(Source code)

绘制单列。

(Source code)

仅绘制 DataFrame 的选定类别。

(Source code)