Skip to content

Commit a85c113

Browse files
committed
Add what's new entry.
1 parent 78ca288 commit a85c113

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Additional format string options in `~matplotlib.axes.Axes.bar_label`
2+
---------------------------------------------------------------------
3+
4+
The ``fmt`` argument of `~matplotlib.axes.Axes.bar_label` now accepts
5+
{}-style format strings:
6+
7+
.. code-block:: python
8+
9+
import matplotlib.pyplot as plt
10+
11+
fruit_names = ["Coffee", "Salted Caramel", "Pistachio"]
12+
fruit_counts = [4000, 2000, 7000]
13+
14+
fig, ax = plt.subplots()
15+
bar_container = ax.bar(fruit_names, fruit_counts)
16+
ax.set(ylabel='pints sold', title='Gelato sales by flavor', ylim=(0, 8000))
17+
ax.bar_label(bar_container, fmt='{:,.0f}')
18+
19+
It also accepts callables:
20+
21+
.. code-block:: python
22+
23+
animal_names = ["Lion", "Gazelle", "Cheetah"]
24+
mph_speed = [50, 60, 75]
25+
26+
fig, ax = plt.subplots()
27+
bar_container = ax.bar(animal_names, mph_speed)
28+
ax.set(ylabel='speed in MPH', title='Running speeds', ylim=(0, 80))
29+
ax.bar_label(
30+
bar_container, fmt=lambda x: '{:.1f} km/h'.format(x * 1.61)
31+
)

0 commit comments

Comments
 (0)