How to remove margins from Matplotlib bar chart?
You can set the limits of the axes to -.5 and len(df)-.5 to avoid the margins of the bar chart.
-.5
len(df)-.5
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()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.