I have a list of Tuples like this :
list_months = [ ('A', 'January'),
('A', 'January'),
('A', 'January'), # Total 10 instances of ('A', 'January')
('A', 'March'),
('A', 'March'),
('A', 'March'),
('A', 'February'),
('A', 'February'),
.............
('B', 'January'),
('B', 'January'), # Total 15 instances of ('B', 'January')
('B', 'July'),
('B', 'July'),
............. ]
This was obtained via a Pandas dataframe using :
for index, val in b['Incident Reported Date Time'].iteritems():
list_months.append((index, str(val)))
I want to be able to generate a MatPlotLib graph such that :
X-Axis -> Months
Y-Axis -> Volume
Multiple Colored Lines -> Each representing 'A', 'B', 'C', etc.
For example in this picture the Red line would represent 'A' and the blue line 'B'.
Since there are 10 of ('A', 'January') it shows the red line on 10 at the Y-Axis for the month of January and there are 15 of ('B', January') so it shows the blue line at 15 at the Y-Axis for the month of January.
How can I generate this and the legend dynamically in matplotlib for Python3 ?
The graph should be line graphs like in the example image.


pandas. If you store your data in a pandas DataFrame you will be able to use its grouping and plotting abilities to do this task.for index, val in b['Incident Reported Date Time'].iteritems(): list_months.append((index, str(val)))matplotlib, not MatPlotLib. Check the website.