2016-07-26 123 views
2

我的数据集是这样的:一个Python列表与6号[23948.30,23946.20,23961.20,23971.70,23956.30,23987.30]蟒/ matplotlib/seaborn-箱线图上的数据点的x轴

我希望他们作为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

回答

2

我回答在其他职位这个问题为好,但我会为了以防万一它贴在这里。我还添加了一些我觉得可能更接近你想要达到的目标。

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

不要让我知道它是否符合你所期待的。

+0

非常感谢你..但这感觉就像它有很长的胡须。你能否在箱形图下添加x轴(点位于x轴上)?类似于我在海豹身上所拥有的东西? – KKlalala

+0

它有很长的胡须,因为你的数据有很高的差异:)。要添加x轴,只需从代码中移除下面的代码:ax.spines ['bottom']。set_color('none') – Andreq

+0

我试过了,效果不好。让我再澄清一点这个问题! – KKlalala