python/matplotlib/seaborn- x 轴上带有数据点的箱线图

标签 python matplotlib plot boxplot seaborn

我的数据集是这样的:一个包含6个数字的python列表[23948.30, 23946.20, 23961.20, 23971.70, 23956.30, 23987.30]

我希望它们成为 x 轴上方的水平箱线图,以 [23855 和 24472] 作为 x 轴的限制(没有 y 轴)。

x 轴还将包含数据中的点。

(因此箱线图和 x 轴具有相同的比例)

我还希望箱线图显示图片中的平均数。

现在我只能得到水平箱线图。 (我还希望 x 轴显示整数而不是 xx+2.394e)

现在这是我的代码:

`

def box_plot(circ_list, wear_limit):
    print circ_list
    print wear_limit

    fig1 = plt.figure()
    plt.boxplot(circ_list, 0, 'rs', 0)
    plt.show()

`

enter image description here

我现在正在尝试的Seaborn代码:

def box_plot(circ_list, wear_limit):
    print circ_list
    print wear_limit

    #fig1 = plt.figure()
    #plt.boxplot(circ_list, 0, 'rs', 0)
    #plt.show()

    fig2 = plt.figure()

    sns.set(style="ticks")

    x = circ_list
    y = []
    for i in range(0, len(circ_list)):
        y.append(0)

    f, (ax_box, ax_line) = plt.subplots(2, sharex=True,
                                        gridspec_kw={"height_ratios": (.15, .85)})

    sns.boxplot(x, ax=ax_box)
    sns.pointplot(x, ax=ax_line, ay=y)

    ax_box.set(yticks=[])
    ax_line.set(yticks=[])
    sns.despine(ax=ax_line)
    sns.despine(ax=ax_box, left=True)

    cur_axes = plt.gca()
    cur_axes.axes.get_yaxis().set_visible(False)
    sns.plt.show()

enter image description here

最佳答案

我也在另一篇文章中回答了这个问题,但为了以防万一,我将其粘贴到这里。我还添加了一些我认为可能更接近您想要实现的目标的内容。

l = [23948.30, 23946.20, 23961.20, 23971.70, 23956.30, 23987.30]

def box_plot(circ_list):
    fig, ax = plt.subplots()
    plt.boxplot(circ_list, 0, 'rs', 0, showmeans=True)
    plt.ylim((0.28, 1.5))
    ax.set_yticks([])
    labels = ["{}".format(int(i)) for i in ax.get_xticks()]
    ax.set_xticklabels(labels)
    ax.spines['right'].set_color('none')
    ax.spines['top'].set_color('none')
    ax.spines['left'].set_color('none')
    ax.spines['bottom'].set_position('center')
    ax.spines['bottom'].set_color('none')
    ax.xaxis.set_ticks_position('bottom')
    plt.show()

box_plot(l)

结果:

Your box-plot

请告诉我它是否符合您正在寻找的内容。

关于python/matplotlib/seaborn- x 轴上带有数据点的箱线图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38595612/

相关文章:

python - 如何为cython(.pyx)文件启用PyCharm类型检查器功能?

python - 自定义 sharex 刻度标签

r - 解析ggplot2的注释中的两个符号(==4==2*2)

python - 使用一个 pyaudio 流进行数据读取和写入

python - 如何使用 python 程序获取包的 Yum 依赖项列表。这里的软件包本身是 CentOS 5.5 上可用的一个软件包更新

python - SpaCy 的匹配器正则表达式不匹配字符串

python - 使用 python 和 seaborn 的错误栏上的顶部和底部线

python - 如何在 wxpython 中使用 Matplotlib.animation?

r - 用ggplot绘制表函数对象?

python - 同一图中的两个不同图形