用pandas重采样的时间序列d填充matplotlib中的条形图空白

2024-05-29 04:58:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我有如下代码:

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')

结果是这样一个情节:

enter image description here

我怎样才能使横杆跨越轴线,使它们之间没有间隙?在


Tags: 代码fromtestimportpandasdfdataget
1条回答
网友
1楼 · 发布于 2024-05-29 04:58:59

使用^{}关键字参数。因为您要每周进行一次重采样,所以设置width=7应该可以完成这项工作。在

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

相关问题 更多 >

    热门问题