简体   繁体   English

用熊猫重新采样的时间序列数据填充matplotlib中的条形图空白

[英]Fill bar plot gaps in matplotlib with pandas resampled time series data

I have some code like the follwoing MWE: 我有一些像下面的MWE的代码:

import matplotlib.pyplot as plt
import pandas as pd
from pandas_datareader import data

test_df = data.get_data_yahoo('AAPL', start='2015-10-01')
test_df = test_df.resample('W', how='sum')['Volume']
fig, ax = plt.subplots()
ax.bar(test_df.index, test_df, edgecolor='None')

Which results in a plot like this: 结果是这样的情节:

在此处输入图片说明

How can I make the bars span the axis so there are no gaps between them? 如何使条形图跨轴,以便它们之间没有间隙?

Use the width keyword argument. 使用width关键字参数。 Since you're doing a weekly resample, setting width=7 should do the job. 由于您要每周进行一次重采样,因此将width=7设置width=7

ax.bar(test_df.index, test_df, edgecolor='None', width=7)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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