2

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 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

6 Comments

Thank you so much.. but this feel like it has very long whiskers. Can you please add the x axis (with points locate on the x axis) under the box plot? something similar to what I have in seaborn?
It has very long whiskers because your data has a high variance :). To add the x-axis, just remove this line from the code: ax.spines['bottom'].set_color('none')
I tried it does not work well. Let me clarify a little bit more on the question!
I have edited the question again. Thanks a lot for your help! @Andreq
And also I had a related problem: stackoverflow.com/questions/38598654/…
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.