- 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
How do I make bar plots automatically cycle across different colors?
To male bar plots automatically cycle across different colors, we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- Set automatic cycler for different colors.
- Make a Pandas dataframe to plot the bars.
- Use plot() method with kind="bar" to plot the bars.
- To display the figure, use show() method.
Example
import matplotlib.pyplot as plt import pandas as pd plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True plt.rc('axes', prop_cycle=(plt.cycler('color', ['r', 'g', 'b', 'y']))) df = pd.DataFrame(dict(name=["John", "Jacks", "James"], age=[23, 20, 26], marks=[88, 90, 76], salary=[90, 89, 98])) df.set_index('name').plot(kind='bar') plt.show()
Output
Advertisements