Python 重新缩放轴
那个图的轴太长了。有没有办法修改该代码以在-10和10之间缩放轴?您要查找的函数称为Python 重新缩放轴,python,matplotlib,Python,Matplotlib,那个图的轴太长了。有没有办法修改该代码以在-10和10之间缩放轴?您要查找的函数称为xlim和ylim ######## # 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',
xlim
和ylim
########
# 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()
ax.set_xlim([-10, 10])
ax.set_ylim([-10, 10])