【发布时间】:2020-07-08 19:29:59
【问题描述】:
我尝试的每个选项都没有为我的情节显示图例。请帮忙。这是代码,并且在我的所有输入都是简单的 NumPy 数组的情况下,该图可以正常工作。添加图例功能时,角落会出现一个小框,因此我知道该指令正在运行,但其中没有任何内容。我正在使用 Jupyter Notebook,我的其他尝试显示在 # 之后。谁能找到漏洞:
import pandas as pd
import matplotlib.pyplot as plt
ratios = ['Share Price', 'PEG', 'Price to Sales']
final_z_scores = np.transpose(final_z_scores)
print(final_z_scores)
fig = plt.figure(figsize=(6,4))
#plt.plot(ratios, final_z_scores[0], ratios, final_z_scores[1], ratios, final_z_scores[2])
first = plt.plot(ratios, final_z_scores[0])
second = plt.plot(ratios, final_z_scores[1])
#ax.legend((first, second), ('oscillatory', 'damped'), loc='upper right', shadow=True)
ax.legend((first, second), ('label1', 'label2'))
plt.xlabel('Ratio Types')
plt.ylabel('Values')
plt.title('Final Comparisons of Stock Ratios')
plt.legend(loc='upper left')
plt.plot()
plt.show()
【问题讨论】:
标签: python matplotlib legend legend-properties