Issue
I would like to create a graph that plots multiple lines onto one graph.
Here is an example dataframe (my actual dataframe is much larger):
df = pd.DataFrame({'first': [1, 2, 3], 'second': [1, 1, 5], 'Third' : [8,7,9], 'Person' : ['Ally', 'Bob', 'Jim']})
The lines I want plotted are rowwise i.e. a line for Ally, a line for Jim and a line for Bob
Solution
You can use the built-in plotting functions, as soon as the DataFrame has the right shape. The right shape in this case would be Person names as columns and the former columns as index. So all you have to do is to set Person
as the index and transpose:
ax = df.set_index("Person").T.plot()
ax.set_xlabel("My label")
Answered By - mcsoini
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.