Skip to content

Commit 9ccc0c3

Browse files
committed
DOC: Document the behavior of bar() for categorical x data
In particular, mention the different behavior on duplicates compared to using `tick_label` explicitly. Closes matplotlib#29507.
1 parent 3fb9c09 commit 9ccc0c3

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2386,6 +2386,17 @@ def bar(self, x, height, width=0.8, bottom=None, *, align="center",
23862386
The x coordinates of the bars. See also *align* for the
23872387
alignment of the bars to the coordinates.
23882388
2389+
Bars are often used for categorical data, i.e. string labels below
2390+
the bars. You can provide a list of strings directly to x.
2391+
``bar(['A', 'B', 'C'], [1, 2, 3])`` is often a shorter and more
2392+
convenient notation compared to
2393+
``bar(range(3), [1, 2, 3], tick_label=['A', 'B', 'C'])``. They are
2394+
equivalent as long as the names are unique. The explicit *tick_label*
2395+
notation draws the names in the sequence given. However, when having
2396+
duplicate values in categorical *x* data, these values map to the same
2397+
numerical x coordinate, and hence the corresponding bars are drawn on
2398+
top of each other.
2399+
23892400
height : float or array-like
23902401
The height(s) of the bars.
23912402

0 commit comments

Comments
 (0)