seaborn.barplot

    A bar plot represents an estimate of central tendency for a numeric variable with the height of each rectangle and provides some indication of the uncertainty around that estimate using error bars. Bar plots include 0 in the quantitative axis range, and they are a good choice when 0 is a meaningful value for the quantitative variable, and you want to make comparisons against it.

    For datasets where 0 is not a meaningful value, a point plot will allow you to focus on differences between levels of one or more categorical variables.

    It is also important to keep in mind that a bar plot shows only the mean (or other estimator) value, but in many cases it may be more informative to show the distribution of values at each level of the categorical variables. In that case, other approaches such as a box or violin plot may be more appropriate.

    Input data can be passed in a variety of formats, including:

    • Vectors of data represented as lists, numpy arrays, or pandas Series objects passed directly to the , y, and/or hue parameters.
    • A “long-form” DataFrame, in which case the x, y, and hue variables will determine how the data are plotted.
    • A “wide-form” DataFrame, such that each numeric column will be plotted.
    • An array or list of vectors.

    In most cases, it is possible to use numpy or Python objects, but pandas objects are preferable because the associated names will be used to annotate the axes. Additionally, you can use Categorical types for the grouping variables to control the order of plot elements.

    This function always treats one of the variables as categorical and draws data at ordinal positions (0, 1, … n) on the relevant axis, even when the data has a numeric or date type.

    See the for more information.

    参数:x, y, hue:names of variables in data or vector data, optional

    data:DataFrame, array, or list of arrays, optional

    Dataset for plotting. If x and y are absent, this is interpreted as wide-form. Otherwise it is expected to be long-form.

    order, hue_order:lists of strings, optional

    Order to plot the categorical levels in, otherwise the levels are inferred from the data objects.

    estimator:callable that maps vector -> scalar, optional

    Statistical function to estimate within each categorical bin.

    ci:float or “sd” or None, optional

    Size of confidence intervals to draw around estimated values. If “sd”, skip bootstrapping and draw the standard deviation of the observations. If None, no bootstrapping will be performed, and error bars will not be drawn.

    n_boot:int, optional

    Number of bootstrap iterations to use when computing confidence intervals.

    units:name of variable in data or vector data, optional

    orient:“v” | “h”, optional

    Orientation of the plot (vertical or horizontal). This is usually inferred from the dtype of the input variables, but can be used to specify when the “categorical” variable is a numeric or when plotting wide-form data.

    Color for all of the elements, or seed for a gradient palette.

    :palette name, list, or dict, optional

    Colors to use for the different levels of the hue variable. Should be something that can be interpreted by color_palette(), or a dictionary mapping hue levels to matplotlib colors.

    saturation:float, optional

    Proportion of the original saturation to draw colors at. Large patches often look better with slightly desaturated colors, but set this to 1 if you want the plot colors to perfectly match the input color spec.

    errcolor:matplotlib color

    Color for the lines that represent the confidence interval.

    errwidth:float, optional

    capsize:float, optional

    Width of the “caps” on error bars.

    dodge:bool, optional

    When hue nesting is used, whether elements should be shifted along the categorical axis.

    ax:matplotlib Axes, optional

    Axes object to draw the plot onto, otherwise uses the current Axes.

    kwargs:key, value mappings

    Other keyword arguments are passed through to plt.bar at draw time.

    返回值:ax:matplotlib Axes

    Returns the Axes object with the plot drawn onto it.

    See also

    Show the counts of observations in each categorical bin.Show point estimates and confidence intervals using scatterplot glyphs.Combine a categorical plot with a class:FacetGrid.

    Examples

    Draw a set of vertical bar plots grouped by a categorical variable:

    1. >>> import seaborn as sns
    2. >>> sns.set(style="whitegrid")
    3. >>> tips = sns.load_dataset("tips")

    Draw a set of vertical bars with nested grouping by a two variables:

    1. >>> ax = sns.barplot(x="day", y="total_bill", hue="sex", data=tips)

    Draw a set of horizontal bars:

    1. >>> ax = sns.barplot(x="tip", y="day", data=tips)

    http://seaborn.pydata.org/_images/seaborn-barplot-3.png

    Control bar order by passing an explicit order:

    Use median as the estimate of central tendency:

    1. >>> from numpy import median

    http://seaborn.pydata.org/_images/seaborn-barplot-5.png

    Show the standard error of the mean with the error bars:

    1. >>> ax = sns.barplot(x="day", y="tip", data=tips, ci=68)

    Show standard deviation of observations instead of a confidence interval:

    1. >>> ax = sns.barplot(x="day", y="tip", data=tips, ci="sd")

    http://seaborn.pydata.org/_images/seaborn-barplot-7.png

    Add “caps” to the error bars:

    Use a different color palette for the bars:

    1. >>> ax = sns.barplot("size", y="total_bill", data=tips,

    http://seaborn.pydata.org/_images/seaborn-barplot-9.png

    Use hue without changing bar position or width:

    1. >>> tips["weekend"] = tips["day"].isin(["Sat", "Sun"])
    2. >>> ax = sns.barplot(x="day", y="total_bill", hue="weekend",
    3. ... data=tips, dodge=False)

    Plot all bars in a single color:

    1. >>> ax = sns.barplot("size", y="total_bill", data=tips,
    2. ... color="salmon", saturation=.5)

    http://seaborn.pydata.org/_images/seaborn-barplot-11.png

    Use plt.bar keyword arguments to further change the aesthetic:

    Use to combine a barplot() and a . This allows grouping within additional categorical variables. Using catplot() is safer than using directly, as it ensures synchronization of variable order across facets:

    1. >>> g = sns.catplot(x="sex", y="total_bill",
    2. ... hue="smoker", col="time",