How does the x coordinates work for plt.bar()?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How does the x coordinates work for plt.bar()?

Sreyan Chakravarty
I am unable to understand how the  plt.bar() function actually works.

Take the following code for example:

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

What does it mean by shift bars by 5 in the plt.bar() call? Does it mean by 5 pixels? 5%? 5% of what? 

These measurements make no sense. Can someone explain to me how this works?
--
Regards,
Sreyan Chakravarty

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: How does the x coordinates work for plt.bar()?

Paul Hobson-2
Five of the same units of your x-axis, which in this case, is points on someone's grade.
-Paul

On Fri, Sep 6, 2019 at 12:32 PM Sreyan Chakravarty <[hidden email]> wrote:
I am unable to understand how the  plt.bar() function actually works.

Take the following code for example:

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

What does it mean by shift bars by 5 in the plt.bar() call? Does it mean by 5 pixels? 5%? 5% of what? 

These measurements make no sense. Can someone explain to me how this works?
--
Regards,
Sreyan Chakravarty
_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users