I have the following data in a pandas dataframe
date template score
0 20140605 0 0.138786
1 20140605 1 0.846441
2 20140605 2 0.766636
3 20140605 3 0.259632
4 20140605 4 0.497366
5 20140606 0 0.138139
6 20140606 1 0.845320
7 20140606 2 0.762876
8 20140606 3 0.261035
9 20140606 4 0.498010
For every day there will be 5 templates and each template will have a score.
I want to plot the date in the x axis and score in the y axis and a separate line graph for each template in the same figure.
Is it possible to do this using matplotlib?
Set the figure size and adjust the padding between and around the subplots. Make a 2D potentially heterogeneous tabular data using Pandas DataFrame class, where the column are x, y and equation. Get the reshaped dataframe organized by the given index such as x, equation, and y. Use the plot() method to plot the lines.
You can use the groupby method:
data.groupby("template").plot(x="date", y="score")
I think the easiest way to plot this data with all the lines on the same graph is to pivot it such that each "template" value is a column:
pivoted = pandas.pivot_table(data, values='score', columns='template', index='date')
# Now there will be an index column for date and value columns for 0,1,2,3,4
pivoted.plot()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With