Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3f08f38

Browse filesBrowse 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 #29507.
1 parent 3fb9c09 commit 3f08f38
Copy full SHA for 3f08f38

File tree

1 file changed

+22
-0
lines changed
Filter options

1 file changed

+22
-0
lines changed

‎lib/matplotlib/axes/_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.py
+22Lines changed: 22 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
@@ -2701,6 +2712,17 @@ def barh(self, y, width, height=0.8, left=None, *, align="center",
27012712
The y coordinates of the bars. See also *align* for the
27022713
alignment of the bars to the coordinates.
27032714
2715+
Bars are often used for categorical data, i.e. string labels below
2716+
the bars. You can provide a list of strings directly to *y*.
2717+
``bar(['A', 'B', 'C'], [1, 2, 3])`` is often a shorter and more
2718+
convenient notation compared to
2719+
``bar(range(3), [1, 2, 3], tick_label=['A', 'B', 'C'])``. They are
2720+
equivalent as long as the names are unique. The explicit *tick_label*
2721+
notation draws the names in the sequence given. However, when having
2722+
duplicate values in categorical *y* data, these values map to the same
2723+
numerical y coordinate, and hence the corresponding bars are drawn on
2724+
top of each other.
2725+
27042726
width : float or array-like
27052727
The width(s) of the bars.
27062728

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.