在一张图中实时绘制多个图

时间:2021-07-15 17:36:34

标签: python python-3.x pandas matplotlib graph

我写了一个代码

from pandas.core.frame import DataFrame
from pynse import *
import numpy as np
import matplotlib.pyplot as plt

company_list = ['WIPRO', 'TATAMOTORS', 'TCS', 'SBIN', 'RELIANCE', 'ONGC', 'MRF', 'MARUTI', 'ICICIBANK', 'HDFCBANK', 'DIVISLAB', 'CIPLA', 'COLPAL']
company_name = 'ZEEL'
company_list = ['SBILIFE']
nse=Nse()


#----------------
expiry_year = 2021
expiry_month = 7
expiry_date = 29
strike_price = 1040
ce_pe = "PE"
#----------------


def test():
    main_df = pd.DataFrame()
    for company_name in company_list:
        # print(nse.get_quote(company_name))
        lastPrice = nse.get_quote(company_name)['lastPrice']
        chain = nse.option_chain(company_name, expiry=dt.date(expiry_year, expiry_month, expiry_date))
        # print(chain.columns)
        premium = chain.loc[chain['%s.strikePrice'%ce_pe] == strike_price]['%s.lastPrice'%ce_pe].iloc[0]
        implied_volatility = chain.loc[chain['%s.strikePrice'%ce_pe] == strike_price]['%s.impliedVolatility'%ce_pe].iloc[0]
        implied_volatility = chain.loc[chain['%s.strikePrice'%ce_pe] == strike_price]['%s.impliedVolatility'%ce_pe].iloc[0]
        traded_volume = chain.loc[chain['%s.strikePrice'%ce_pe] == strike_price]['%s.totalTradedVolume'%ce_pe].iloc[0]
        open_interest = chain.loc[chain['%s.strikePrice'%ce_pe] == strike_price]['%s.openInterest'%ce_pe].iloc[0]
        return [lastPrice, premium, implied_volatility, traded_volume, open_interest]


data_list = test()
print("lastPrice : ", data_list[0])
print("premium : ", data_list[1])
print("implied_volatility : ", data_list[2])
print("traded_volume : ", data_list[3])
print("open_interest : ", data_list[4])

我想在一个图中创建 4 个图形。第一个图表应实时打印 3 个图表中的 lastPrice 和 premium 以及其他 3 个(implied_volatility、traded_volume 和 open_interest)。

我还希望实时滚动并在图形上显示最多 10 个值。我试过 matplotlib 但没有成功。

任何帮助将不胜感激

0 个答案:

没有答案