【发布时间】:2020-09-15 00:28:15
【问题描述】:
我正在尝试在 matplotlib 中创建一个带有 2 个条形图的条形图子图,在 x 轴上。我创建了以下图像:
这是使用以下代码创建的:
import pandas as pd
import matplotlib.pyplot as plt
ydata1=pd.Series.from_array([451,505])
ydata2=pd.Series.from_array([839,286])
fig, (ax1, ax2) = plt.subplots(1,2,sharex='col',sharey='row')
xlabels = ['x1', 'x2']
ax1.bar(xlabels,ydata1, 0.4, align='center') #0.4 is width of bar
ax2.bar(xlabels,ydata2, 0.4, align='center')
plt.show()
我遇到的问题是我想调整条形的位置,使它们对称且与每个刻面的边缘等距间隔,而不是在每个刻面的左右边缘(因为它们目前是)。有什么办法可以调整matplotlib中条的位置,使它们对称?
谢谢
【问题讨论】:
标签: python pandas matplotlib subplot