mplfinance 中是否有等价于 plt.scatter 的东西?如何在 mplfinance 中绘制数据点图表?
is there an equivalent of plt.scatter in mplfinance? How to you graph data points in mplfinance?
mplfinance 中 plt.scatter 的等价物是什么???
我正在使用 mpl finance 绘制股票价格图。
def graph():
file = 'prices1.xlsx'
data = pd.read_excel(file, sheet_name = stockQuote)
data.Date = pd.to_datetime(data.Date)
data = data.set_index('Date')
mpf.plot(data, type = 'candle', mav = (100), tight_layout = True)
这个
graph('AAPL')
应该给我 AAPL 烛台价格图。
我还有另一个 excel sheet 的买卖价格。看起来像这样
myPrices = pd.read_excel('transactions.xlsx')
Date
Symbol
Action
Price
2020-03-20
AAPL
Buy
80
2021-03-05
AAPL
Sell
120
2020-03-20
TSLA
Buy
400
我知道 matplotlib 有这个:
plt.scatter(myPrices.index, myPrices['Buy'], label = 'Buy', market = '^', color = 'green')
plt.scatter(myPrices.index, myPrices['Sell'], label = 'Sell', market = 'v', color = 'red')
因为我想绘制图表 'AAPL',所以我想读取 transaction.xlsx 中的日期,其中 Symbol = 'AAPL'。我想买的时候在MPLFINANCE GRAPH中用绿色箭头^表示,卖的时候用红色箭头v表示。但是,我只知道matplotlib中的这个方法。 mplfinance 是否有等价物?请帮忙 T-T
mplfinace 中的散点图不能单独使用,但可以与烛台结合使用。您的数据被修改为每月数据并用作样本数据。数据上需要注意一点,时序数据的长度必须相同,否则会出错。这个页面不错reference.
import pandas as pd
import numpy as np
import io
data = '''
Date Symbol Action Price
2020-03-01 AAPL Buy 80
2020-04-01 AAPL Sell 130
2020-05-01 AAPL Buy 90
2020-06-01 AAPL Sell 125
2020-07-01 AAPL Buy 125
2020-08-01 AAPL Sell 110
2020-09-01 AAPL Buy 95
2020-10-01 AAPL Sell 125
2020-11-01 AAPL Buy 125
2020-12-01 AAPL Sell 140
2021-01-01 AAPL Buy 115
2021-02-01 AAPL Sell 135
'''
df = pd.read_csv(io.StringIO(data), delim_whitespace=True)
df['Date'] = pd.to_datetime(df['Date'])
buy = df[df['Action'] == 'Buy']
buy2 = df[['Date']].merge(buy,how='outer')
sell = df[df['Action'] == 'Sell']
sell2 = df[['Date']].merge(sell,how='outer')
import mplfinance as mpf
import yfinance as yf
data = yf.download("AAPL", interval='1mo', start="2020-03-01", end="2021-03-01")
data.dropna(how='any', inplace=True)
ap = [mpf.make_addplot(buy2['Price'], type='scatter', marker='^', markersize=200, color='g'),
mpf.make_addplot(sell2['Price'], type='scatter', marker='v', markersize=200, color='r')
]
mpf.plot(data, type='candle', ylabel='Candle', addplot=ap, volume=False)
mplfinance 中 plt.scatter 的等价物是什么???
我正在使用 mpl finance 绘制股票价格图。
def graph():
file = 'prices1.xlsx'
data = pd.read_excel(file, sheet_name = stockQuote)
data.Date = pd.to_datetime(data.Date)
data = data.set_index('Date')
mpf.plot(data, type = 'candle', mav = (100), tight_layout = True)
这个
graph('AAPL')
应该给我 AAPL 烛台价格图。
我还有另一个 excel sheet 的买卖价格。看起来像这样
myPrices = pd.read_excel('transactions.xlsx')
Date | Symbol | Action | Price |
---|---|---|---|
2020-03-20 | AAPL | Buy | 80 |
2021-03-05 | AAPL | Sell | 120 |
2020-03-20 | TSLA | Buy | 400 |
我知道 matplotlib 有这个:
plt.scatter(myPrices.index, myPrices['Buy'], label = 'Buy', market = '^', color = 'green')
plt.scatter(myPrices.index, myPrices['Sell'], label = 'Sell', market = 'v', color = 'red')
因为我想绘制图表 'AAPL',所以我想读取 transaction.xlsx 中的日期,其中 Symbol = 'AAPL'。我想买的时候在MPLFINANCE GRAPH中用绿色箭头^表示,卖的时候用红色箭头v表示。但是,我只知道matplotlib中的这个方法。 mplfinance 是否有等价物?请帮忙 T-T
mplfinace 中的散点图不能单独使用,但可以与烛台结合使用。您的数据被修改为每月数据并用作样本数据。数据上需要注意一点,时序数据的长度必须相同,否则会出错。这个页面不错reference.
import pandas as pd
import numpy as np
import io
data = '''
Date Symbol Action Price
2020-03-01 AAPL Buy 80
2020-04-01 AAPL Sell 130
2020-05-01 AAPL Buy 90
2020-06-01 AAPL Sell 125
2020-07-01 AAPL Buy 125
2020-08-01 AAPL Sell 110
2020-09-01 AAPL Buy 95
2020-10-01 AAPL Sell 125
2020-11-01 AAPL Buy 125
2020-12-01 AAPL Sell 140
2021-01-01 AAPL Buy 115
2021-02-01 AAPL Sell 135
'''
df = pd.read_csv(io.StringIO(data), delim_whitespace=True)
df['Date'] = pd.to_datetime(df['Date'])
buy = df[df['Action'] == 'Buy']
buy2 = df[['Date']].merge(buy,how='outer')
sell = df[df['Action'] == 'Sell']
sell2 = df[['Date']].merge(sell,how='outer')
import mplfinance as mpf
import yfinance as yf
data = yf.download("AAPL", interval='1mo', start="2020-03-01", end="2021-03-01")
data.dropna(how='any', inplace=True)
ap = [mpf.make_addplot(buy2['Price'], type='scatter', marker='^', markersize=200, color='g'),
mpf.make_addplot(sell2['Price'], type='scatter', marker='v', markersize=200, color='r')
]
mpf.plot(data, type='candle', ylabel='Candle', addplot=ap, volume=False)