python/matplotlib/seaborn- boxplot on an x axis wi

2019-02-27 10:54发布

My data set is like this: a python list with 6 numbers [23948.30, 23946.20, 23961.20, 23971.70, 23956.30, 23987.30]

I want them to be be a horizontal box plot above an x axis with[23855 and 24472] as the limit of the x axis (with no y axis).

The x axis will also contain points in the data.

(so the box plot and x axis have the same scale)

I also want the box plot show the mean number in picture.

Now I can only get the horizontal box plot. (And I also want the x-axis show the whole number instead of xx+2.394e)

Here is my code now:

`

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 code I am trying right now:

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

1条回答
祖国的老花朵
2楼-- · 2019-02-27 11:38

I answered this question in the other post as well, but I will paste it here just in case. I also added something that I feel might be closer to what you are looking to achieve.

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)

The result:

Your box-plot

Do let me know if it correspond to what you were looking for.

查看更多
登录 后发表回答