 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- 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

Advertisements
 