gpt4 book ai didi

python - 使用 matplotlib 一次输出两个图形

转载 作者:行者123 更新时间:2023-11-28 18:28:06 26 4
gpt4 key购买 nike

简而言之,我想编写一个函数来输出 scatter matrixboxplot一次在 python 中。我想我会通过创建一个带有 2x1 绘图数组的图形来做到这一点。但是,当我使用 Jupyter 笔记本运行代码时:

def boxplotscatter(data):
f, ax = plt.subplots(2, 1, figsize = (12,6))
ax[0] = scatter_matrix(data, alpha = 0.2, figsize = (6,6), diagonal = 'kde')
ax[1] = data.boxplot()

我得到,使用名为 pdf 的数据:

enter image description here

这与我的预期不符——我想输出散点矩阵及其下方的箱线图,而不是两个空网格和嵌入散点矩阵中的箱线图。

关于修复此代码的想法?

最佳答案

我认为您只需要将轴作为绘图函数的参数传递即可。

f, ax = plt.subplots(2, 1, figsize = (12,6))
def boxplotscatter(data, ax):
ax[0] = scatter_matrix(data, alpha = 0.2, figsize = (6,6), diagonal = 'kde')
ax[1] = data.boxplot()

关于python - 使用 matplotlib 一次输出两个图形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39740109/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com