Skip to content

Commit a411ef9

Browse files
plotting too much data warning, and example images
1 parent edec6eb commit a411ef9

11 files changed

+35
-0
lines changed
118 KB
Loading
152 KB
Loading
81.3 KB
Loading
40.4 KB
Loading
135 KB
Loading
125 KB
Loading

examples/images/less_data.jpg

129 KB
Loading

examples/images/less_data_code.jpg

69.5 KB
Loading

examples/scratch_pad/too_much_data.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import glob
2+
import mplfinance as mpf
3+
import pandas as pd
4+
5+
6+
df = pd.read_csv('../data/yahoofinance-GOOG-20040819-20180120.csv',index_col=0,parse_dates=True)
7+
8+
tdf = df.iloc[0:2000,:]
9+
mpf.plot(tdf,type='candle',tight_layout=True,datetime_format='%b %d, %H:%M')
10+
11+
df = pd.read_csv('../data/SP500_NOV2019_IDay.csv',index_col=0,parse_dates=True)
12+
13+
tdf = df.loc['2019-11-05 10:47':'2019-11-05 13:13',:]
14+
mpf.plot(tdf,type='candle',tight_layout=True,datetime_format='%b %d, %H:%M')
15+
16+

src/mplfinance/_arg_validators.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import datetime
55
from mplfinance._helpers import _list_of_dict
66
import matplotlib as mpl
7+
import warnings
78

89
def _check_and_prepare_data(data, config):
910
'''
@@ -28,6 +29,21 @@ def _check_and_prepare_data(data, config):
2829
if not isinstance(data.index,pd.core.indexes.datetimes.DatetimeIndex):
2930
raise TypeError('Expect data.index as DatetimeIndex')
3031

32+
if (len(data.index) > config['warn_too_much_data'] and
33+
(config['type']=='candle' or config['type']=='ohlc' or config['type']=='hollow_and_filled')
34+
):
35+
warnings.warn('\n\n ================================================================= '+
36+
'\n\n WARNING: YOU ARE PLOTTING SO MUCH DATA THAT IT MAY NOT BE'+
37+
'\n POSSIBLE TO SEE DETAILS (Candles, Ohlc-Bars, Etc.)'+
38+
'\n For more information see:'+
39+
'\n - https://github.com/matplotlib/mplfinance/wiki/Plotting-Too-Much-Data'+
40+
'\n '+
41+
'\n TO SILENCE THIS WARNING, set `type=\'line\'` in `mpf.plot()`'+
42+
'\n OR set kwarg `warn_too_much_data=N` where N is an integer '+
43+
'\n LARGER than the number of data points you want to plot.'+
44+
'\n\n ================================================================ ',
45+
category=UserWarning)
46+
3147
# We will not be fully case-insensitive (since Pandas columns as NOT case-insensitive)
3248
# but because so many people have requested it, for the default column names we will
3349
# try both Capitalized and lower case:

0 commit comments

Comments
 (0)