每次循环迭代时,我都尝试向图例中添加一个条目a
和b
是str
,我想以某种方式更新循环中的图例,这样它会plt.plot
它们并更新给定的a
和b
的图例。有什么办法我能做到吗?谢谢
plt.figure(figsize=(8.5, 4.5))
for a,b in zip(assets,buckets):
df_temp = pd.read_excel(filename, sheet_name = a)
df_temp = df_temp[['SPOT', b]]
df_temp.dropna(inplace=True)
df_temp_change = np.log(df_temp.values[:-1] / df_temp.values[1:])
x1 = df_temp_change[:,0]
x2 = df_temp_change[:,1]
t_corr_vectors = threshold_corr(x1, x2, q_ts)
# t_corr_vectors1 = threshold_corr(x1, x2, q_ts1)
# t_corr_vectors2 = threshold_corr(x1, x2, q_ts2)
plt.plot(q_ts, t_corr_vectors)
plt.legend((t_corr_vectors),(a + "-" + b))
plt.title("Threshold Correlations")
plt.ylabel("Correlations")
plt.xlabel("Quantiles")
plt.savefig("TEST.jpg")
可以在plot函数中设置标签,然后激活末尾的图例:
相关问题 更多 >
编程相关推荐