8000 Merge pull request #29514 from meeseeksmachine/auto-backport-of-pr-29… · matplotlib/matplotlib@ec3c21f · GitHub
[go: up one dir, main page]

Skip to content

Commit ec3c21f

Browse files
authored
Merge pull request #29514 from meeseeksmachine/auto-backport-of-pr-29511-on-v3.10.x
Backport PR #29511 on branch v3.10.x (DOC: Document the behavior of bar() for categorical x data)
2 parents c0a9260 + de3cbd2 commit ec3c21f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2391,6 +2391,17 @@ def bar(self, x, height, width=0.8, bottom=None, *, align="center",
23912391
The x coordinates of the bars. See also *align* for the
23922392
alignment of the bars to the coordinates.
23932393
2394+
Bars are often used for categorical data, i.e. string labels below
2395+
the bars. You can provide a list of strings directly to *x*.
2396+
``bar(['A', 'B', 'C'], [1, 2, 3])`` is often a shorter and more
2397+
convenient notation compared to
2398+
``bar(range(3), [1, 2, 3], tick_label=['A', 'B', 'C'])``. They are
2399+
equivalent as long as the names are unique. The explicit *tick_label*
2400+
notation draws the names in the sequence given. However, when having
2401+
duplicate values in categorical *x* data, these values map to the same
2402+
numerical x coordinate, and hence the corresponding bars are drawn on
2403+
top of each other.
2404+
23942405
height : float or array-like
23952406
The height(s) of the bars.
23962407
@@ -2706,6 +2717,17 @@ def barh(self, y, width, height=0.8, left=None, *, align="center",
27062717
The y coordinates of the bars. See also *align* for the
27072718
alignment of the bars to the coordinates.
27082719
2720+
Bars are often used for categorical data, i.e. string labels below
2721+
the bars. You can provide a list of strings directly to *y*.
2722+
``barh(['A', 'B', 'C'], [1, 2, 3])`` is often a shorter and more
2723+
convenient notation compared to
2724+
``barh(range(3), [1, 2, 3], tick_label=['A', 'B', 'C'])``. They are
2725+
equivalent as long as the names are unique. The explicit *tick_label*
2726+
notation draws the names in the sequence given. However, when having
2727+
duplicate values in categorical *y* data, these values map to the same
2728+
numerical y coordinate, and hence the corresponding bars are drawn on
2729+
top of each other.
2730+
27092731
width : float or array-like
27102732
The width(s) of the bars.
27112733

0 commit comments

Comments
 (0)
0