gpt4 book ai didi

Python:使用 Datareader 截断列宽

转载 作者:太空宇宙 更新时间:2023-11-04 04:23:14 24 4
gpt4 key购买 nike

我正在设置一个包含股票价格交易量matplotlib图表。该图将从 pandas datareader 获取数据。

我的问题是数量与价格相比非常高,因此它们的图表看起来非常不成比例,而且由于库存不断变化,我无法缩放它。

我如何截断每列的宽度,而不是说每行显示“10”位数字而只显示“5”?

我试图将每一列分隔成一个字符串并使用拆分,但我的问题是找到一种方法将它们追加回数据框。

-- 旁注:如果有一种方法可以将成交量作为条形图,而价格是一条线,那就太棒了。

start = datetime.date(2017, 12, 29)
end = datetime.date(2018, 12, 29)
f = web.DataReader('GOOGL', 'iex', start, end)


f = f.head[10]
price = f.open
volume = f.volume
time = f.shape[0]

plt.plot(time,price)
plt.plot(time, volume)
plt.show()

最佳答案

您可以设置不同刻度的双轴。

start = datetime.date(2017, 12, 29)
end = datetime.date(2018, 12, 29)
import pandas_datareader.data as web
f = web.DataReader('GOOGL', 'iex', start, end)
f = f.head()

fig, ax1 = plt.subplots()
ax1.bar(x = f.index, height = f.volume/1000, width = 0.3)
ax1.set_ylabel('volumn in 1000s', color='b')
ax1.tick_params('y', colors='b')

ax2 = ax1.twinx()
ax2.plot(f.index, f.open, 'g')
ax2.set_ylabel('open price', color='g')
ax2.tick_params('y', colors='g')

fig.tight_layout()
plt.show()

enter image description here

关于Python:使用 Datareader 截断列宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54062959/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com