Вместо этого вы можете использовать plt.figlegend()
, что даст вам такой вывод
![enter image description here](https://i.stack.imgur.com/swPSo.png)
Или позвоните plt.legend()
после каждого сюжета, чтобы добавить легенду к каждому субплоту индивидуально,
import matplotlib.pyplot as plt
x = [1,2,3,4,5,-1-2]
y = [-1,5, 100, -2, 50, 100]
t = [100, 110, 120, 130, 140, 150]
plt.figure()
ax1 = plt.subplot(3, 1, 1)
plt.title('Demo');
ax1.plot(t,x, 'b.:', label="Demo") # Showing top Horizontal
plt.legend()
ax2 = plt.subplot(3, 1, 2, sharex=ax1)
ax2.plot(t,y, 'b.:', label="Demo1") # Not showing up
plt.legend()
ax3 = plt.subplot(3, 1, 3, sharex=ax1)
ax3.plot(t,t, 'b.:', label="Demo2") # This is perfect how I wanted
plt.legend()
plt.show()
![enter image description here](https://i.stack.imgur.com/Zoanb.png)
Если это не совсем то, что вы хотите, есть другие методы, описанные в ответы на этот вопрос