Python:绘制带有自动Y缩放的烛台 [英] Python: Plot candlesticks with automatic Y zoom
问题描述
我正在寻找一个Python绘图库,该库允许我通过鼠标滚轮滚动(或类似操作)和X缩放(缩放时自动缩放的Y轴)来绘制带有X缩放的烛台(最好是OHLC条形式).
作为我正在寻找的示例,tradingview.com完美地做到了这一点.参见 https://uk.tradingview.com/chart/?symbol=NASDAQ:NDX .通过单击左上角附近的烛台图标并选择条形",可以看到OHLC条形.
Plotly几乎可以做到这一点. plotly.graph_objs中的Ohlc类提供了OHLC条形图,默认的rangelider是X缩放的一个不错的功能(也可以轻松启用鼠标滚轮滚动).但是据我所知,Python中没有自动Y缩放功能( https://plot.ly/python/ohlc-charts/ >
我熟悉的另一个选项是PyQtGraph,它具有不错的缩放功能,但不支持烛台图.使用此方法将涉及对我自己的烛台对象进行编码.
我不知道有各种各样的Python绘图库.那里有什么可以立即使用的支持吗?谁能提供示例代码来干净地做到这一点?
这是在finplot中执行的方法:
import yfinance as yf
import finplot as fplt
df = yf.download('^NDX', start='2018-01-01', end='2020-04-29')
print(df)
fplt.candlestick_ochl(df[['Open','Close','High','Low']])
fplt.show()
免责声明:我是作者. Finplot具有自动Y缩放功能,使用干净的api快速且自以为是.请参见示例此处.
I am looking for a Python plotting library that allows me to plot candlesticks (preferably the OHLC bars variant) with X zoom via mousewheel scrolling (or similar) and an automatically scaled Y axis when zooming.
As an example of what I am looking for, tradingview.com does this perfectly. See https://uk.tradingview.com/chart/?symbol=NASDAQ:NDX. OHLC bars can be seen by clicking the candlestick icon near the top left and selecting 'Bars'.
Plotly is almost able to do this. The Ohlc class in plotly.graph_objs give the OHLC bars, and the default rangeslider is a nice feature for X zoom (mousewheel scrolling can also be easily enabled). However automatic Y scaling is not available in Python as far as I can see (Y-axis autoscaling with x-range sliders in plotly), thus zooming in on a section of data makes it appear flat. Example code - https://plot.ly/python/ohlc-charts/
Another option I am familiar with is PyQtGraph, which has nice zoom features but does not have support for candlestick plots. Using this would involve coding my own candlestick object.
There are a wide range of Python plotting libraries out there that I don't know. Is there anything out there that has out of the box support for this? Can anyone provide example code to do this cleanly?
This is how to do it in finplot:
import yfinance as yf
import finplot as fplt
df = yf.download('^NDX', start='2018-01-01', end='2020-04-29')
print(df)
fplt.candlestick_ochl(df[['Open','Close','High','Low']])
fplt.show()
Disclaimer: I am the author. Finplot has auto-Y-scaling, is fast and opinionated with a clean api. See examples here.
这篇关于Python:绘制带有自动Y缩放的烛台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!