【发布时间】:2020-10-29 10:17:40
【问题描述】:
我正在尝试通过plt.xlim(-1.5, 1.5) 和plt.ylim(-1.5, 1.5) 扩展情节。你能解释一下为什么情节的范围不符合预期吗?
import pandas as pd
from sklearn import preprocessing
from sklearn import decomposition
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_style('whitegrid')
import numpy as np
# Change the image format to svg for better quality
%config InlineBackend.figure_format = 'svg'
decathlon = pd.read_csv("https://raw.githubusercontent.com/leanhdung1994/Deep-Learning/main/decathlon.txt", sep='\t')
decathlon_scaled = decathlon.copy()
decathlon_scaled.iloc[:, 0:10] = preprocessing.scale(decathlon.iloc[:, 0:10])
pca_scaled = decomposition.PCA(n_components = 10).fit(decathlon_scaled.iloc[:, 0:10])
decathlon_scaled_pca = pca_scaled.transform(decathlon_scaled.iloc[:, 0:10])
decathlon_scaled_pca_nor = decathlon_scaled_pca / np.sqrt((decathlon_scaled_pca ** 2).sum(axis = 0))
decathlon_scaled_nor = decathlon_scaled.iloc[:, 0:10] / np.sqrt((decathlon_scaled.iloc[:, 0:10] ** 2).sum(axis = 0))
decathlon_corr_circle = decathlon_scaled_pca_nor.T.dot(decathlon_scaled_nor)
decathlon_corr_circle
tmp = np.transpose(decathlon_corr_circle)[:, 0:2]
tmp = pd.DataFrame(tmp)
tmp.index = decathlon.columns[0:10]
fig = plt.figure(figsize = 1 * np.array(plt.rcParams['figure.figsize'])) # This is to have bigger plot
ax = sns.scatterplot(data = tmp,
x = tmp[0], y = tmp[1])
for i in range(10):
plt.arrow(0, 0, tmp[0][i], tmp[1][i],
color = 'orange', head_width = 0.025, length_includes_head = True)
circle = plt.Circle((0, 0), 1, color='g', fill=False)
ax.add_artist(circle)
plt.xlim(-1.5, 1.5)
plt.ylim(-1.5, 1.5)
plt.axis('equal')
【问题讨论】:
-
@JohanC 我刚刚尝试过你的建议,但它不起作用。
-
@JohanC 它仍然无法正常工作。它不会扩展 y 轴上的范围。
标签: python-3.x matplotlib seaborn