Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correlation Matrix labels in Python

I'm using Python3. The top of my matrix is a problem, all the labels are overlapping so you can't read them. How do I fix this?

Here is my code:

import matplotlib.pyplot as plt
import pandas
import numpy
budget_adj  revenue_adj
mov_data = ['popularity', 'budget', 'revenue', 'runtime', 'vote_average', 
'release_year']
#data = pd.read_csv(url, names=names)
correlations = db.corr()
# plot correlation matrix
fig = plt.figure()
ax = fig.add_subplot(111)
subplotsize=[8.,8.]
figuresize=[10.,10.]   
left = 0.5*(1.-subplotsize[0]/figuresize[0])
right = 1.-left
bottom = 0.5*(1.-subplotsize[1]/figuresize[1])
top = 1.-bottom
fig.subplots_adjust(left=left,right=right,bottom=bottom,top=top)
cax = ax.matshow(correlations, vmin=-1, vmax=1)
fig.colorbar(cax)
ticks = numpy.arange(0,5,1)
ax.set_xticks(ticks)
ax.set_yticks(ticks)
ax.set_xticklabels(mov_data)
ax.set_yticklabels(mov_data)
plt.show()

An here is what it looks like:

enter image description here

like image 562
EP31121PJ Avatar asked Sep 19 '25 11:09

EP31121PJ


1 Answers

Just rotate the labels by, say, 45 degrees: ax.set_xticklabels(mov_data,rotation=45).

like image 171
DYZ Avatar answered Sep 22 '25 01:09

DYZ