python/matplotlib/seaborn- boxplot on an x axis with data points

你。 提交于 2019-12-31 03:41:07

问题


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()

`

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()


回答1:


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:

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



来源:https://stackoverflow.com/questions/38595612/python-matplotlib-seaborn-boxplot-on-an-x-axis-with-data-points

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!