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:
Just rotate the labels by, say, 45 degrees: ax.set_xticklabels(mov_data,rotation=45)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With