如果通过子图matplotlib绘制2个图,则不显示boxplot

时间:2018-06-13 21:20:19

标签: python matplotlib plot boxplot

我正在尝试使用Python中的matplotlib并排绘制散点图和框图。

预期结果应该是左侧的散点图,而右侧的框图则是。但我的boxplot无法正确显示。我得到如下输出:

enter image description here 如图所示,箱线图错误地显示为丑陋的散点图。下面请找我的代码。我非常感谢任何想法或建议。谢谢你的时间。

def multiple_plot(X, y, outliers_low, outliers_high,attribute_name):
    import matplotlib.pyplot as plt
    import pylab
    import seaborn as sns
    #plt.scatter(X,y)
    fig,(ax1, ax2) = plt.subplots(ncols=2,sharey=False,sharex=False,figsize=(18,5))
    ax1.set_ylim([outliers_low,outliers_high])
    sns.regplot(x=X,y=y,ax=ax1)
    ax1.set(xlabel=attribute_name)

    sns.boxplot(x=X, y=y,width=0.5, whis=2,ax=ax2)
    ax2.set(xlabel=attribute_name)
    ax2.set(ylabel='NPI');

    plt.tight_layout()
    plt.show()

0 个答案:

没有答案