- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Setting Different Bar color in Matplotlib
We can first create bars and then, by using set_color, we can set the color of the bars.
Steps
Pass two lists consisting of four elements, into the bars method argument.
Step 1 returns bars.
Return values (0, 1, 2, 3) can be set with different colors, using set_color() method. Green, Black, Red color will be set and one bar will have the default color.
To show the figure, use plt.show() method.
Example
from matplotlib import pyplot as plt bars = plt.bar([1, 2, 3, 4], [1, 2, 3, 4]) bars[0].set_color('green') bars[1].set_color('black') bars[2].set_color('red') plt.show()
Output
- Related Articles
- Setting different error bar colors in barplot in Matplotlib
- Setting the spacing between grouped bar plots in Matplotlib
- Automatically setting Y-axis limits for a bar graph using Matplotlib
- Setting Color Property in CSS
- Set Max value for color bar on Seaborn heatmap using Matplotlib
- Setting up Background Color in CSS
- Setting Text Color using CSS
- Setting Background color for Tkinter in Python
- Setting Text Color Working with CSS
- Setting up Background Color using CSS
- Setting Y-axis in Matplotlib using Pandas
- Setting the Color of Links using CSS
- Setting the Location Color Stops using CSS
- How to change the color of a single bar if a condition is true (Matplotlib)?
- Setting active subplot using axes object in Matplotlib

Advertisements