重新缩放轴

时间:2018-07-13 03:36:47

标签: python matplotlib

########
# Plot #
########

fig = plt.figure(figsize = (8,8))
ax = fig.add_subplot(1,1,1) 

ax.set_xlabel('PC 1', fontsize = 15)
ax.set_ylabel('PC 2', fontsize = 15)
ax.set_title('2 Component PCA', fontsize = 20)

targets = [1, 0, -1]
colors = ['r', 'g', 'b']
for target, color in zip(targets,colors):
    indicesToKeep = finalDf['Label_Capture_Spread'] == target
    ax.scatter(finalDf.loc[indicesToKeep, 'PC 1']
               , finalDf.loc[indicesToKeep, 'PC 2']
               , c = color
               , s = 20)
ax.legend(targets)
ax.grid()

该图的轴方向过于延伸。有没有办法修改该代码以在-10和10之间缩放轴?

1 个答案:

答案 0 :(得分:1)

您要查找的功能称为xlimylim

ax.set_xlim([-10, 10])
ax.set_ylim([-10, 10])