Note
Go to the end to download the full example code.
Bar color demo#
This is an example showing how to control bar color and legend entries
using the color and label parameters of bar
.
Note that labels with a preceding underscore won't show up in the legend.
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
fruits = ['apple', 'blueberry', 'cherry', 'orange']
counts = [40, 100, 30, 55]
bar_labels = ['red', 'blue', '_red', 'orange']
bar_colors = ['tab:red', 'tab:blue', 'tab:red', 'tab:orange']
ax.bar(fruits, counts, label=bar_labels, color=bar_colors)
ax.set_ylabel('fruit supply')
ax.set_title('Fruit supply by kind and color')
ax.legend(title='Fruit color')
plt.show()
Total running time of the script: (0 minutes 1.019 seconds)