I have a dataset composed for 330 values where I would like to show the correlation between speed and error. If I show the plot as it is, it is difficult to check the correlation. Then, I would like to average the error based on a speed range. I mean, each bar representing the average of the speed between 0 and 1, 1 and 2, and so on. My current code is like this.
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.pyplot import figure
figure(figsize=(24, 12), dpi=80)
# Make a random dataset:
height = summ['Error']
bars = summ['MeanSpeed']
y_pos = np.arange(len(bars))
# Create bars
plt.bar(y_pos, height)
# Create names on the x-axis
plt.xticks(y_pos, bars)
# Show graphic
plt.show()
How can I average the values for each speed range?
I would like something like this:
I create this by doing:
m1=np.mean(summ[(summ['MeanSpeed']>=0)&(summ['MeanSpeed']<=1)])[4]
m2=np.mean(summ[(summ['MeanSpeed']>=1)&(summ['MeanSpeed']<=2)])[4]
m3=np.mean(summ[(summ['MeanSpeed']>=2)&(summ['MeanSpeed']<=3)])[4]
m4=np.mean(summ[(summ['MeanSpeed']>=3)&(summ['MeanSpeed']<=4)])[4]
plt.bar([1,2,3,4], [m1,m2,m3,m4])
plt.show()