0

Plotting a matrix of correlation scatters from a data frame with

axes = scatter_matrix(df, alpha=0.5, diagonal='kde')
corr = df.corr().as_matrix()
for i, j in zip(*plt.np.triu_indices_from(axes, k=1)):
    axes[i, j].annotate("%.3f" %corr[i,j], (0.8, 0.8), xycoords='axes fraction', ha='center', va='center')

(thank you to Ohjeah pandas scatter matrix display correlation coefficient)

However, since I have nine attributes I'd like to increase the size of the figure as currently the text is overlapping. Here is what I have tried, to no avail:

axes = scatter_matrix(df, alpha=0.5, diagonal='kde')
corr = df.corr().as_matrix()
plt.figure(figsize=(10,10))
for i, j in zip(*plt.np.triu_indices_from(axes, k=1)):
    axes[i, j].annotate("%.3f" %corr[i,j], (0.8, 0.8), xycoords='axes fraction', ha='center', va='center')
axes = scatter_matrix(df, alpha=0.5, diagonal='kde')
corr = df.corr().as_matrix()
for i, j in zip(*plt.np.triu_indices_from(axes, figsize=(10,10) k=1)):
    axes[i, j].annotate("%.3f" %corr[i,j], (0.8, 0.8), xycoords='axes fraction', ha='center', va='center')

All three of these iterations produce identical plots. Any idea how to increase figure size for this?

lcleary
  • 65
  • 6
  • Note that plt.figure creates a fully new figure, independent from the figure created via scatter_matrix. `fig.set_size_inches(...)` would change an already created figure. – JohanC Mar 05 '22 at 13:34
  • 1
    Did you read the first comment on the answer you linked? scatter_matrix accepts figsize as a parameter – JohanC Mar 05 '22 at 13:36

0 Answers0