[Matplotlib-users] Does xticks start marking from 0 only?

Thomas Caswell tcaswell at gmail.com
Sat Sep 7 16:39:01 EDT 2019


When you use `plt.xticks` you are saying "please put ticks at these
locations", thus you will only see ticks at [0, 10, .., 100], independent
of what your limits are.

Tom

On Sat, Sep 7, 2019 at 3:22 AM Sreyan Chakravarty <sreyan32 at gmail.com>
wrote:

> 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
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users at python.org
> https://mail.python.org/mailman/listinfo/matplotlib-users
>


-- 
Thomas Caswell
tcaswell at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20190907/32a006cf/attachment.html>


More information about the Matplotlib-users mailing list