hvplot运行失败求助:箱线图代码执行报错排查
排查hvplot箱线图代码报错问题
运行代码
loan_amnt_box = data.hvplot.box( y='loan_amnt', subplots=True, by='loan_status', width=300, height=350, title="Loan Status by Loan Amount ", xlabel='Loan Status', ylabel='Loan Amount' ) installment_box = data.hvplot.box( y='installment', subplots=True, by='loan_status', width=300, height=350, title="Loan Status by Installment", xlabel='Loan Status', ylabel='Installment' ) loan_amnt_box + installment_box
报错信息


错误原因及解决方法
- 核心问题:同时使用
subplots=True和by参数时,hvplot返回的是单个BoxWhisker对象,而非支持+拼接的布局类对象,而BoxWhisker本身不支持+运算符,因此触发AttributeError。 - 解决方法:
- 移除
subplots=True参数:使用by参数时,hvplot会自动按分组生成子图并返回可直接拼接的Layout对象,修改后代码:loan_amnt_box = data.hvplot.box( y='loan_amnt', by='loan_status', width=300, height=350, title="Loan Status by Loan Amount ", xlabel='Loan Status', ylabel='Loan Amount' ) installment_box = data.hvplot.box( y='installment', by='loan_status', width=300, height=350, title="Loan Status by Installment", xlabel='Loan Status', ylabel='Installment' ) loan_amnt_box + installment_box - 若需保留
subplots=True,手动将对象包装进Layout:from holoviews import Layout loan_amnt_box = data.hvplot.box( y='loan_amnt', subplots=True, by='loan_status', width=300, height=350, title="Loan Status by Loan Amount ", xlabel='Loan Status', ylabel='Loan Amount' ) installment_box = data.hvplot.box( y='installment', subplots=True, by='loan_status', width=300, height=350, title="Loan Status by Installment", xlabel='Loan Status', ylabel='Installment' ) Layout([loan_amnt_box, installment_box])
- 移除
内容的提问来源于stack exchange,提问作者Michael
相关产品推荐
相关产品推荐

