Python中的相关矩阵标签

时间:2018-02-03 21:39:44

标签: python plot

我正在使用Python3。我的矩阵的顶部是一个问题,所有标签都重叠,所以你不能阅读它们。我该如何解决这个问题?

这是我的代码:

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()

这就是它的样子:

enter image description here

2 个答案:

答案 0 :(得分:0)

只需将标签旋转45度:ax.set_xticklabels(mov_data,rotation=45)

答案 1 :(得分:0)

使用rotation

set_xticklabels参数
ax.set_xticklabels(mov_data, rotation=45)