5

I'm creating a big scatter matrix and want to change the text such that it is neat, aligned, doesn't overlap etc. To do this I want to explore reducing the font size and changing the text rotation (and anything else reasonable). How could I do this?

The following attempt has not worked:

scatter_matrix = pd.scatter_matrix(
    data,
    figsize  = [15, 15],
    marker   = ".",
    s        = 0.2,
    diagonal = "kde"
)
plt.xticks(fontsize = 2, rotation = -90)
plt.yticks(fontsize = 2)
plt.savefig("scatter_matrix.jpg", dpi = 700)
BlandCorporation
  • 1,324
  • 1
  • 15
  • 33
  • 2
    Looks like you already know how to change font size and text rotation. What's your actual question? – Stop harming Monica Apr 04 '17 at 20:45
  • 3
    "has not worked" is not a sufficient problem description. What is the outcome, in how far is it not what you want? Be precise about your requirement ("I want a neat plot" is impossible to give an answer to). – ImportanceOfBeingErnest Apr 04 '17 at 20:49
  • @Goyo I tried to illustrate that the font size and text rotation was not changing by posting images of the results. The solution by piRSquared indicates that one needs to iterate over all of the plots changing their characteristics individually. – BlandCorporation Apr 05 '17 at 11:23
  • @ImportanceOfBeingErnest I tried to illustrate that the font size and text rotation was not changing buy posting images. I'll try to be clearer in future. – BlandCorporation Apr 05 '17 at 11:24

1 Answers1

12

The reason it isn't working is that scatter_matrix is a numpy array of axes. plt can't work on all those axes at once. You need to iterate through them and do your adjustments.

scatter_matrix = pd.scatter_matrix(
    data,
    figsize  = [15, 15],
    marker   = ".",
    s        = 0.2,
    diagonal = "kde"
)

for ax in scatter_matrix.ravel():
    ax.set_xlabel(ax.get_xlabel(), fontsize = 20, rotation = 90)
    ax.set_ylabel(ax.get_ylabel(), fontsize = 20, rotation = 0)

enter image description here

piRSquared
  • 285,575
  • 57
  • 475
  • 624