我的图例在python绘图中不起作用
我正在运行以下代码:我的图例在python绘图中不起作用,python,plot,legend,Python,Plot,Legend,我正在运行以下代码: plt.figure(10) plt.legend() plt.title('MLP Regression 510th test case') plt.xlabel('Frequency') plt.ylabel('Shielding Effectivness [dB]') plt.plot(xax,mlp_predict[510,:], color = 'red', label = "Predicted") plt.scatter(xax,y_tes
plt.figure(10)
plt.legend()
plt.title('MLP Regression 510th test case')
plt.xlabel('Frequency')
plt.ylabel('Shielding Effectivness [dB]')
plt.plot(xax,mlp_predict[510,:], color = 'red', label = "Predicted")
plt.scatter(xax,y_test.iloc[510,:], color = 'black', label = "Actual")
不幸的是,它产生了这样一个传说:
我已经尝试将绘图命令移动到代码的顶部,以及plt.legend()
在打印命令的正上方。似乎什么都不管用
谢谢你的帮助
import numpy as np
import matplotlib.pyplot as plt
x = range(8)
y1 = range(1, 80, 10)
y2 = range(1, 160, 20)
plt.figure(10)
plt.title('MLP Regression 510th test case')
plt.xlabel('Frequency')
plt.ylabel('Shielding Effectivness [dB]')
plt.plot(y1, label ="y = 10x")
plt.plot(y2, label ="y = 20x")
plt.legend(loc ="lower left")
plt.show()
我认为你必须把传奇放在最下面而不是最上面。Like图例必须在plot命令之后。此外,您还可以通过指定适当的位置来调整图例的位置。欲了解更多信息,请访问[matplotlib.pyplot.legend的官方文档,谢谢!伙计,我感到很惊讶,谢谢,如果你愿意,那么你可以接受这个答案。