Python Forum
Help with plot legends in subplots
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with plot legends in subplots
#1
Hi guys,

I wrote this code to subplot two graphs:

f,axarr = plt.subplots(2, sharex=True)
axarr[0].plot(X,Tt,label='Tt')
plt.legend()
axarr[1].plot(X,B,label='B')
plt.legend()
plt.show()
The problem is that the legend of the first graphic 'Tt', doesn't appear on the final figure:

[Image: qB4CUKtSaoAvv66f6]

I appreciate the help.
Reply
#2
I am not familiar with matplotlib but I've found this. I hope it will help
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
(Feb-06-2017, 01:59 PM)wavic Wrote: I am not familiar with matplotlib but I've found this. I hope it will help

That's worked perfectly !! Thanks.

I changed the lines 3 and 5 and now I have legend in both graphs:

f,axarr = plt.subplots(2, sharex=True)
axarr[0].plot(X,Tt,label='Tt')
legend = axarr[0].legend()
axarr[1].plot(X,B,label='B')
legend = axarr[1].legend()
plt.show()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to loop through code to plot seaborn line plots across multiple subplots eyavuz21 0 1,652 Dec-05-2022, 10:46 AM
Last Post: eyavuz21
  Nested for loops: Iterating over columns of a DataFrame to plot on subplots dm222 0 1,697 Aug-19-2022, 11:07 AM
Last Post: dm222
Question Error with MatPlotLib subplots Danno 8 3,402 Apr-01-2022, 12:23 AM
Last Post: Danno
  How to plot intraday data of several days in one plot mistermister 3 2,896 Dec-15-2020, 07:43 PM
Last Post: deanhystad
  how to create subplots in for loop? python_newbie09 1 5,895 Sep-25-2019, 02:29 PM
Last Post: stullis
  How to plot vertically stacked plot with same x-axis and SriMekala 0 1,916 Jun-12-2019, 03:31 PM
Last Post: SriMekala
  Subplots on one figure SarahColombo96 0 1,739 Feb-09-2019, 01:09 PM
Last Post: SarahColombo96
  Change distance and title postion in subplots Mark3232 2 2,831 Jul-19-2018, 10:10 AM
Last Post: Mark3232

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020