Skip to content Skip to sidebar Skip to footer

How To Create Subplots With Pandas Scatter Matrix

So I'm trying to create a subplot of pandas scatter matrices but have run into a bit of a wall. I've looked around at other similar questions, but none of the answers seemed to fix

Solution 1:

pandas doesn't currently do that, although it has a promising ax argument:

iris = pd.DataFrame.from_csv('iris.csv')
chicks = pd.DataFrame.from_csv('ChickWeight.csv')
import matplotlib.pyplot as plt

fig, axs = plt.subplots(2)

#iris.plot.scatter('PL', 'PW', ax = axs[0])        
#chicks.plot.scatter('Diet', 'Chick', ax = axs[1]) # This is fine.

pd.scatter_matrix(iris, ax=axs[0], alpha=0.2)
pd.scatter_matrix(chicks, ax=axs[1], alpha=0.2)    # This clears axes unexpectedly.

plt.savefig('two_pd_scatter.png')

gives warning

/usr/local/lib/python2.7/site-packages/pandas/tools/plotting.py:3303: UserWarning: To output multiple subplots, the figure containing the passed axes is being cleared

"is being cleared", UserWarning)

Note that it's specifically clearing the whole figure, not just the passed axes.

I'd fix this by generating four tight-margin, systematically named figures for the scatter matrices and set up a document (TeX, whatever) that imports those figures in the right places and with the right title.

Post a Comment for "How To Create Subplots With Pandas Scatter Matrix"