Reputation: 33
I am running the following code:
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")
and it produces this, unfortunately without a legend:
I have tried moving the plotting commands to the top of the code, as well as the plt.legend() to just above the plotting commands. Nothing seems to work.
Thanks for your help!
Upvotes: 1
Views: 102
Reputation: 401
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()
I think you must put legend at bottom rather than at top. Like legend must be after plot command. Also, you can adjust the location of legend by specifying the appropriate location. For further information you may visit [official documentation of matplotlib.pyplot.legend
Upvotes: 1