简体   繁体   English

从多个数据框中将多个图转换为pdf

[英]Multiple plots to pdf from multiple dataframes

I would like to periodically create pdfs with stocks of interest to me and related graphs for each stock. 我想定期用我感兴趣的股票以及每只股票的相关图表创建pdf文件。

For the moment, I have one dataframe for each technical indicator (price, moving average, exponential moving average, etc.) and would like to plot for each time series their relevant information from each dataframe. 目前,我对每个技术指标(价格,移动平均线,指数移动平均线等)都有一个数据框,并希望针对每个时间序列绘制每个数据框的相关信息。

Until now, I have used bokeh and I am able to plot what I want but for each ticker individually... 到现在为止,我已经使用了bokeh,并且能够针对每个行情自动绘制所需的内容...

The code I have is this: 我的代码是这样的:

# Import dataframes from import_data.py
prices = pd.read_pickle('prices.pkl')
date = prices.index
# price 20, 50, 80 MA
ma20 = pd.rolling_mean(prices, window=20)
ma50 = pd.rolling_mean(prices, window=50)
ma80 = pd.rolling_mean(prices, window=80)
# price with 20EMA+Bollinger Bands - 20MA
ema20 = pd.ewma(prices, span=20)
bbandsup = pd.ewma(prices, span=20) + 2 * pd.ewmstd(prices, span=20)
bbandslo = pd.ewma(prices, span=20) - 2 * pd.ewmstd(prices, span=20)


plot = figure(title="Price Chart and Technical Indicators", x_axis_label='Date', y_axis_label='Price')

plot.line(date, prices['SPY'], legend='Price', line_width=2)
plot.line(date, ema20['SPY'], legend='EMA-20', line_width=2, line_color="red")
plot.line(date, ma20['SPY'], legend='EA-20', line_width=2, line_color="green")
plot.line(date, bbandsup['SPY'], legend='Bollinger', line_width=2, line_color="black", line_dash="4 4")
plot.line(date, bbandslo['SPY'], legend='Bollinger', line_width=2, line_color="black", line_dash="4 4")

show(plot)

prices dataframe has a structure of date as index and the column headers are the ticker strings. price数据框具有日期结构作为索引,列标题是代码字符串。 For example, the first column header is SPY, the second is AAPL, etc... 例如,第一列标题是SPY,第二列标题是AAPL,等等。

I would like to be able to print all of them into pdf before attacking the multiple plot beast. 我希望能够在攻击多剧情野兽之前将它们全部打印为pdf。

Thanks in advance! 提前致谢!

Multiple plots are not more complicated than what you already have - you just have to call figure for each plot and combine the resulting plots using Bokeh layouts . 多个图并不比您现在拥有的要复杂-您只需为每个图调用figure ,然后使用Bokeh布局将得到的图合并即可。

PDF generation, however, is more involved. 但是,PDF的生成会涉及更多。 Bokeh has functions to render documents as PNG and SVG, but there's not PDF generation yet. Bokeh具有将文档呈现为PNG和SVG的功能,但还没有生成PDF。 You can either submit a feature request via Github or implement something yourself. 您可以通过Github提交功能请求,也可以自己实施。 In the latter case, you can either generate PNG/SVG files and create PDF documents from them or get inspiration from bokeh.io.export_png and implement direct export to PDF using Selenium and PhantomJS. 在后一种情况下,您可以生成PNG / SVG文件并从中创建PDF文档,也可以从bokeh.io.export_png获取灵感,并使用Selenium和PhantomJS实现直接导出为PDF。

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

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