python - 与 figurefactory 重叠的图
问题描述
我正在尝试绘制一些财务图表,并为此使用了 plotly 库。
我对此很陌生,所以不得不寻找一种方法来做到这一点,并想离线进行,所以我找到了这种方式:
import pandas as pd
pd.core.common.is_list_like = pd.api.types.is_list_like
from pandas_datareader import data as web
import datetime
import fix_yahoo_finance as yf
import plotly
from plotly import figure_factory as ff
import os
yf.pdr_override()
class Stock:
#We need a constructor to get all the data when we create the class
def __init__(self, name): #This needs a string as argument to work
self.name = name
#If we already have the sotcks data we don't download it again
if os.path.exists('stock_prices_yahoo/' + name + '.csv'):
self.df = pd.read_csv('stock_prices_yahoo/' + name + '.csv')
else:
start_date = '1950-01-01'
end_date = datetime.date.today()
df = web.get_data_yahoo(name, start_date, end_date)
df.to_csv('stock_prices_yahoo/' + name + '.csv')
def plot_stock(self): #This will print a plot of the stock prices
fig = ff.create_candlestick(self.df.Open, self.df.High, self.df.Low, self.df.Close, dates = self.df.Date)
fig['layout'].update({
'title': self.name + ' prices',
'yaxis': {'title': 'Price'},
'xaxis': {'title': 'Date'},
})
plotly.offline.plot(fig, filename = self.name + '-candlestick.html', validate = True)
AAPL = Stock('AAPL')
AAPL.plot_stock()
关键是我想在上面重叠一些移动平均线,并且在整个互联网上寻找它之后,人们总是通过 matplotlib 来做。有没有办法用 figure_factory 做到这一点?
解决方案
推荐阅读
- python - 正则表达式 html 动态表
- php - 通过 mysql 查询使用公式:错误
- python - 将数据附加到现有的 Json 文件
- python - 添加字符串值的pyspark中存在的值
- spacy - rasa_nlu spacy 的构建轮失败和thinc 的构建轮失败
- bash - 使用 awk 创建的 bash 变量在 echo 输出中移动
- android - 如何为从图库中选择的多个图像传递一组图像并将它们显示在 Flutter 中的另一个小部件上
- c# - 使用 Web 服务发送 zip 文件
- javascript - 解构和创建新对象
- chart.js - 如何在图表 js 中为每个条形显示不同的产品名称