David
David

Reputation: 1256

How to remove margins from Matplotlib bar chart?

How to remove margins from Matplotlib bar chart?

enter image description here

Upvotes: 5

Views: 5882

Answers (1)

ImportanceOfBeingErnest
ImportanceOfBeingErnest

Reputation: 339052

You can set the limits of the axes to -.5 and len(df)-.5 to avoid the margins of the bar chart.

import matplotlib.pyplot as plt
import pandas as pd
plt.rcParams["patch.force_edgecolor"] = True

df = pd.DataFrame([1,2])
df.plot.bar(width=1)
plt.xlim(-0.5,len(df)-.5)
plt.show()

enter image description here

Upvotes: 14

Related Questions