Skip to content

Commit 972e95c

Browse files
authored
Merge pull request matplotlib#23670 from stefmolin/new-bar-examples
Add bar color demo.
2 parents 2e8231f + c1503d9 commit 972e95c

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
==============
3+
Bar color demo
4+
==============
5+
6+
This is an example showing how to control bar color and legend entries
7+
using the *color* and *label* parameters of `~matplotlib.pyplot.bar`.
8+
Note that labels with a preceding underscore won't show up in the legend.
9+
"""
10+
11+
import matplotlib.pyplot as plt
12+
13+
fig, ax = plt.subplots()
14+
15+
fruits = ['apple', 'blueberry', 'cherry', 'orange']
16+
counts = [40, 100, 30, 55]
17+
bar_labels = ['red', 'blue', '_red', 'orange']
18+
bar_colors = ['tab:red', 'tab:blue', 'tab:red', 'tab:orange']
19+
20+
ax.bar(fruits, counts, label=bar_labels, color=bar_colors)
21+
22+
ax.set_ylabel('fruit supply')
23+
ax.set_title('Fruit supply by kind and color')
24+
ax.legend(title='Fruit color')
25+
26+
plt.show()

0 commit comments

Comments
 (0)