File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
examples/lines_bars_and_markers Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change
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 ()
You can’t perform that action at this time.
0 commit comments