Skip to content

Commit ff38c24

Browse files
multicursor examples; issue #303
1 parent f863495 commit ff38c24

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

examples/scratch_pad/multicursor.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import numpy as np
2+
import matplotlib.pyplot as plt
3+
from matplotlib.widgets import MultiCursor
4+
5+
print('1')
6+
t = np.arange(0.0, 2.0, 0.01)
7+
s1 = np.sin(2*np.pi*t)
8+
s2 = np.sin(4*np.pi*t)
9+
10+
print('2')
11+
fig, (ax1, ax2) = plt.subplots(2, sharex=True)
12+
ax1.plot(t, s1)
13+
ax2.plot(t, s2)
14+
15+
print('3')
16+
multi = MultiCursor(fig.canvas, (ax1, ax2), color='lime', lw=1, horizOn=True, vertOn=True)
17+
print('4')
18+
plt.show()
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import pandas as pd
2+
import mplfinance as mpf
3+
from matplotlib.widgets import MultiCursor
4+
5+
idf = pd.read_csv('../data/SPY_20110701_20120630_Bollinger.csv',index_col=0,parse_dates=True)
6+
df = idf.loc['2011-07-01':'2011-12-30',:]
7+
8+
9+
exp12 = df['Close'].ewm(span=12, adjust=False).mean()
10+
exp26 = df['Close'].ewm(span=26, adjust=False).mean()
11+
12+
macd = exp12 - exp26
13+
14+
signal = macd.ewm(span=9, adjust=False).mean()
15+
histogram = macd - signal
16+
17+
apds = [mpf.make_addplot(exp12,color='lime'),
18+
mpf.make_addplot(exp26,color='c'),
19+
mpf.make_addplot(histogram,type='bar',width=0.7,panel=1,
20+
color='dimgray',alpha=1,secondary_y=False),
21+
mpf.make_addplot(macd,panel=1,color='fuchsia',secondary_y=True),
22+
mpf.make_addplot(signal,panel=1,color='b',secondary_y=True),
23+
]
24+
25+
fig, axlist = mpf.plot(df,type='candle',addplot=apds,figscale=1.1,figratio=(8,5),title='\nMACD',
26+
style='blueskies',volume=True,volume_panel=2,panel_ratios=(6,3,2),returnfig=True)
27+
28+
multi = MultiCursor(fig.canvas, axlist, color='r',lw=1.2)
29+
mpf.show()

0 commit comments

Comments
 (0)