Reputation: 1256
How to remove margins from Matplotlib bar chart?
Upvotes: 5
Views: 5882
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()
Upvotes: 14