I used the following python codes to plot histogram. I need to sort the xlabel b
ID: 3370387 • Letter: I
Question
I used the following python codes to plot histogram. I need to sort the xlabel by value (from small to large: 0,4,5,6,7.....). What codes should I add to sort the xlabel in order of value? Where should I add the line of codes.
Thanks
import thinkstats2
import thinkplot
dataList = list()
F = open("student-mat.csv", "r")
for line in F:
spLine = line.split(",")
dataList.append(spLine[32])
G3hist = thinkstats2.Hist(dataList)
thinkplot.Hist(G3hist)
thinkplot.Show(xlabel='value', ylabel='frequency')
Explanation / Answer
I think you need to put the “sort_values(‘value’)” in your final line of code.
So, the code should now read:
G3hist=thinkstats2.Hist(dataList)
thinkplot.Hist(G3hist)
thinkplot.show(xlabel=‘value’,ylabel=‘frequency’).sort_value(‘value’)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.