- 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 to change the space between bars when drawing multiple barplots in Pandas? (Matplotlib)
To change the space between bars when drawing multiple barplots in Pandas within a group, we can use linewidth in plot() method.
Steps
- Set the figure size and adjust the padding between and around the subplots.
- Make a dictionary with two columns.
- Create a two-dimensional, size-mutable, potentially heterogeneous tabular data.
- Plot the dataframe with plot() method, with linewidth that change the space between the bars.
- Place a legend on the plot.
- To display the figure, use show() method.
Example
import pandas as pd from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True d = {'Column 1': [i for i in range(10)], 'Column 2': [i * i for i in range(10)]} df = pd.DataFrame(d) df.plot(kind='bar', edgecolor='white', linewidth=1) plt.legend(loc="upper left") plt.show()
Output
- Related Articles
- How to change the space between bars in a barplot in R?
- Python matplotlib multiple bars
- How to plot multiple horizontal bars in one chart with matplotlib?
- How to change the attributes of a networkx / matplotlib graph drawing?
- Drawing multiple legends on the same axes in Matplotlib
- Drawing multiple figures in parallel in Python with Matplotlib
- How to remove gaps between bars in Matplotlib bar chart?
- How do I plot hatched bars using Pandas and Matplotlib?
- How to increase the space between bars of a bar plot using ggplot2 in R?
- Drawing lines between two plots in Matplotlib
- How to change the DPI of a Pandas Dataframe Plot in Matplotlib?
- How to change the spacing between ticks in Matplotlib?
- How to adjust the space between legend markers and labels in Matplotlib?
- How to avoid overlapping error bars in matplotlib?
- How to write annotation outside the drawing in data coords in Matplotlib?

Advertisements