

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
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
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
- Related Questions & Answers
- Setting different error bar colors in barplot in Matplotlib
- How to make an Android status bar notification persist across phone reboot?
- How do I create an automatically updating GUI using Tkinter?
- How do I create an automatically updating GUI using Tkinter in Python?
- How do I get interactive plots again in Spyder/Ipython/matplotlib?
- How to make Two activities with different colored status bar in Android.
- How do I make a transparent canvas in HTML5?
- How do I make my string comparison case insensitive?
- How do I make case-insensitive queries on MongoDB?
- How do I automatically download files from a pop up dialog using selenium-python?
- How to give a Pandas/Matplotlib bar graph custom colors?
- How do I change the font size of the scale in Matplotlib plots?
- Plot different colors for different categorical levels using matplotlib
- Different Participants of Defect Life Cycle
- Comparison of different Life Cycle Models
Advertisements