【问题标题】:subplotting missingno library plotssubplotting missingno 库图
【发布时间】:2019-02-19 16:30:23
【问题描述】:

通过msno.matrix() 为 df1 、 df2 、 df3 获取missingno 的子图的最简单方法是什么。我已经检查了this issue 和以下解决方案由于TypeError 'AxesSubplot' object does not support indexing 而没有工作,并根据that issue 更新了pandas 和missingno。

fig = msno.matrix(df)
grid_ax = fig.axes[0]
my_subplots = plt.subplots(2, 2)
my_subplots[0][0] = grid_ax

我在sn-p下面用过但是不成功。我不知道我应该怎么回复ax

#Set up the figure
fig, ax = plt.subplots(nrows=1, ncols=2 , figsize=(8,8) , squeeze=False)

plt.subplot(131) 
msno.matrix(df1)

plt.subplot(132) 
msno.matrix(df2)

plt.subplot(133) 
msno.matrix(df3)

plt.savefig('comparison.png') 
#plt.tight_layout()
plt.show()

请留下一个通用的解决方案,我们可以通过替换不同的 df 我们可以使用它。 祝你有个愉快的夜晚

【问题讨论】:

  • 这是不可能的,因为this line 在内部创建了图形。有像thisthis 这样的变通方法,但它们有不必要的副作用。这里的解决方案类似于this,重新创建matrix 函数并带有传入轴的选项。

标签: python matplotlib subplot


【解决方案1】:

你的错误:

'AxesSubplot' object does not support indexing

我会尝试在 .axes 之后取出索引,如下所示:

fig = msno.matrix(df)
grid_ax = fig.axes

希望对你有帮助

【讨论】:

  • 它对msno.matrix 不起作用并丢弃TypeError: 'Figure' object does not support item assignment
【解决方案2】:

在 Iannes 的回答中添加一点:missingno 文档规定指定inline=False,这将导致missingno 返回底层matplotlib.figure.Figure 对象。

所以提供的代码应该是:

fig = msno.matrix(df, inline=False)
grid_ax = fig.axes

【讨论】:

    猜你喜欢
    • 2022-10-18
    • 2022-01-07
    • 2012-05-17
    • 1970-01-01
    • 1970-01-01
    • 2019-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多