[Matplotlib-users] Does xticks start marking from 0 only?
Sreyan Chakravarty
sreyan32 at gmail.com
Sat Sep 7 03:21:39 EDT 2019
Given the code:
plt.axis([-5, 105, 0, 5]) # x-axis from -5 to 105,
# y-axis from 0 to 5
plt.xticks([10 * i for i in range(11)])
I see xticks only marks from 0, where as the axis starts from -5.
So does xticks only start marking from 0 even though the x-axis starts from
-5 ?
Full Code:
from matplotlib import pyplot as plt
from collections import Counter
grades = [83, 95, 91, 87, 70, 0, 85, 82, 100, 67, 73, 77, 0]
# Bucket grades by decile, but put 100 in with the 90s
histogram = Counter(min(grade // 10 * 10, 90) for grade in grades)
plt.bar([x + 5 for x in histogram.keys()], # Shift bars right by 5
histogram.values(), # Give each bar its correct
height
10, # Give each bar a width of 10
edgecolor=(0, 0, 0)) # Black edges for each bar
plt.axis([-5, 105, 0, 5]) # x-axis from -5 to 105,
# y-axis from 0 to 5
#xticks takes the highest value in the list given and then
plt.xticks([10 * i for i in range(11)]) # x-axis labels at 0, 10, ...,
100
plt.xlabel("Decile")
plt.ylabel("# of Students")
plt.title("Distribution of Exam 1 Grades")
plt.show()
--
Regards,
Sreyan Chakravarty
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20190907/1a7a5bf4/attachment.html>
More information about the Matplotlib-users
mailing list