每次循环迭代时,我都试图向图例添加一个条目。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 函数中设置标签,然后在最后激活图例:
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, label=(a + "-" + b))
plt.legend()
plt.title("Threshold Correlations")
plt.ylabel("Correlations")
plt.xlabel("Quantiles")
plt.savefig("TEST.jpg")
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句