Reputation: 143
I have a file with data that I'm splitting into three categories. I want to display three different "bins" which all display just one number (average of that category).
import csv
import matplotlib.pyplot as plt
import seaborn as sns
c1 = [1, 1, 1, 3, 3, 3] # average 2
c2 = [8, 12] # average 10
c3 = [20, 30, 40] # average 30
sns.set(style='ticks')
plt.hist([(sum(c1)/len(c1)), (sum(c2)/len(c2)), (sum(c3)/len(c3))], bins=8)
plt.show()
Now I know my code doesn't work, I just don't know how to set up something like this that would get me wanted result.
To sum up what I want: on x axes c1, c2, c3. On y axes I want c1 to go to average of that list (2 on y axes for c1), for c2 to 10 and for c3 to 30.
Upvotes: 1
Views: 552
Reputation: 39072
Since you want just the average value for each list, what you need is a bar chart instead of a histogram, with the tick-labels representing c1
, c2
, c3
. Histogram is used to plot a distribution, you need a discrete average bar for each list
import matplotlib.pyplot as plt
import seaborn as sns
c1 = [1, 1, 1, 3, 3, 3] # average 2
c2 = [8, 12] # average 10
c3 = [20, 30, 40] # average 30
sns.set(style='ticks')
plt.bar(range(3), [(sum(c1)/len(c1)), (sum(c2)/len(c2)), (sum(c3)/len(c3))])
plt.xticks(range(3), ['c1', 'c2', 'c3'])
plt.show()
Upvotes: 1