简体   繁体   中英

How to remove margins from Matplotlib bar chart?

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.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM