【发布时间】:2020-06-23 06:22:20
【问题描述】:
我有一个包含观察结果的数据库,然后它有每个 PCA 分析 - PCA 1 和 PCA 2,它们是针对不同日期计算的:
我的目标: 根据这些日期创建 4 个散点图,并根据列“line_leg”为它们着色。
到目前为止我做了什么:
创建了 4 个散点图 -
fig, axes = plt.subplots(nrows=2, ncols=2,figsize=(16, 10))
并尝试以这种方式绘制 ax[0][0] +color :
targets = ['100 D','100 C','70 D','70 C','40 D', '40 C']
colors = ['tab:blue','tab:green','tab:purple','tab:cyan','tab:red','tab:orange']
#colors = ['lawngreen','royalblue','tab:green','midnightblue','tab:red','tab:orange']
for target, color in zip(targets,colors):
#goes to line. and check of 1,2,3,4,5,6 are true or false, 6 times total, and if true gives the color.
indicesToKeep = df_PCA_all['line_leg'] == target
ax[0][0].scatter(df_PCA_all.iloc[:,3:5].loc[indicesToKeep, 'PCA1_19']
, df_PCA_all.iloc[:,3:5].loc[indicesToKeep, 'PCA2_19']
, c = color
, s = 100
, label=target)
ax.legend(targets)
ax.grid()
但我得到了错误:
TypeError: 'AxesSubplot' 对象不可下标
我的最终目标是用 df 中的数据绘制这 4 个数字,每个数字显示不同的日期(19、21、28、03),并根据 line_leg 的值着色。
【问题讨论】:
标签: python matplotlib scatter-plot subplot