python - 如果通过子图 matplotlib 绘制 2 个图,boxplot 不显示
问题描述
我正在尝试通过在 Python 中使用 matplotlib 并排绘制散点图和箱线图。
预期的结果应该是左侧的散点图,而右侧的箱线图。但是我的箱线图显示不正确。我得到如下输出:
如图所示,箱线图被错误地显示为丑陋的散点图。请在下面找到我的代码。我将不胜感激任何想法或建议。谢谢你的时间。
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()
解决方案
推荐阅读
- mdc-components - 如何在 lit 元素中使用 MDC 组件?
- r - 在 SpatialPolygonDataFrame 中计算人口
- migration - 用于优化构建的 Angular 6 升级运行时问题
- scala - 如何创建涉及某些功能在范围内的“块”的 DSL?
- python - 在 Python3 上使用 Pandas 未对齐数据框
- r - Plot dates with regular interval in R
- python-3.x - 如何使用烧瓶获取图像上传到服务器的元数据。
- angular - 角度自定义控件 - 星级 - 来自输入的值
- jquery - Jquery根据选项更改div
- c++ - 缺少链表的测试用例