1

What is the easiest way to get subplots of missingno via msno.matrix() for df1 , df2, df3 . I already checked this issue and below solution didn't work due to TypeError 'AxesSubplot' object does not support indexing and updated pandas and missingno based on that issue.

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

I used below snippet but was unsuccessful. I don't know how shuold I returen the 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()

Please leave a general solution we can just by replacing different df we can use it. Have a nice evening

Tom Ron
  • 5,906
  • 3
  • 22
  • 38
Mario
  • 1,631
  • 2
  • 21
  • 51
  • 1
    It's not possible due to [this line](https://github.com/ResidentMario/missingno/blob/1d67f91fbab0695a919c6bb72c796db57024e0ca/missingno/missingno.py#L51) creating the figure internally. There are workarounds like [this](https://stackoverflow.com/a/46906599/4124317) or [this](https://stackoverflow.com/a/45812071/4124317) but they have unwanted side effects. The solution here would be similar to [this](https://stackoverflow.com/questions/53600211/figure-into-a-subplot-matplotlib/53600501#53600501), recreating the `matrix` function with the option to pass in an axes. – ImportanceOfBeingErnest Feb 19 '19 at 16:43

2 Answers2

0

Your error:

'AxesSubplot' object does not support indexing

I would try to take out the index after the .axes, like this:

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

Hope it helps

  • It didn't work for `msno.matrix` and throw out `TypeError: 'Figure' object does not support item assignment` – Mario Jul 25 '19 at 21:54
0

To add a bit to Iannes' answer: missingno docs stipulate to specify inline=False, which will cause missingno to return the underlying matplotlib.figure.Figure object.

So the provided code should be:

fig = msno.matrix(df, inline=False)
grid_ax = fig.axes
Danil
  • 99
  • 1
  • 5