Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added customized labels to axises and in legend #28

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

setup(
name='trendln',
version="0.1.10",
version="0.1.11",
description='Support and Resistance Trend lines Calculator for Financial Analysis',
long_description=long_description,
long_description_content_type='text/markdown',
Expand Down
19 changes: 11 additions & 8 deletions trendln/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,13 +753,16 @@ def calc_all(idxs, h, isMin):

def plot_sup_res_date(hist, idx, numbest = 2, fromwindows = True, pctbound=0.1,
extmethod = METHOD_NUMDIFF, method=METHOD_NSQUREDLOGN, window=125,
errpct = 0.005, hough_scale=0.01, hough_prob_iter=10, sortError=False, accuracy=1):
errpct = 0.005, hough_scale=0.01, hough_prob_iter=10, sortError=False, accuracy=1,
title='Prices with Support/Resistance Trend Lines', y_axis_label='Price', y_label='Close Price'):
import matplotlib.ticker as ticker
return plot_support_resistance(hist, ticker.FuncFormatter(datefmt(idx)), numbest, fromwindows,
pctbound, extmethod, method, window, errpct, hough_scale, hough_prob_iter, sortError, accuracy)
pctbound, extmethod, method, window, errpct, hough_scale, hough_prob_iter, sortError, accuracy, title, y_axis_label, y_label)

def plot_support_resistance(hist, xformatter = None, numbest = 2, fromwindows = True,
pctbound=0.1, extmethod = METHOD_NUMDIFF, method=METHOD_NSQUREDLOGN,
window=125, errpct = 0.005, hough_scale=0.01, hough_prob_iter=10, sortError=False, accuracy=1):
window=125, errpct = 0.005, hough_scale=0.01, hough_prob_iter=10, sortError=False, accuracy=1,
title='Prices with Support/Resistance Trend Lines', y_axis_label='Price', y_label='Close Price'):
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
ret = calc_support_resistance(hist, extmethod, method, window, errpct, hough_scale, hough_prob_iter, sortError, accuracy)
Expand All @@ -774,15 +777,15 @@ def plot_support_resistance(hist, xformatter = None, numbest = 2, fromwindows =
disp = [(hist[0], minimaIdxs, pmin, 'yo', 'Avg. Support', 'y--'), (hist[1], maximaIdxs, pmax, 'bo', 'Avg. Resistance', 'b--')]
dispwin = [(hist[0], minwindows, 'Support', 'g--'), (hist[1], maxwindows, 'Resistance', 'r--')]
disptrend = [(hist[0], mintrend, 'Support', 'g--'), (hist[1], maxtrend, 'Resistance', 'r--')]
plt.plot(range(len_h), hist[0], 'k--', label='Low Price')
plt.plot(range(len_h), hist[1], 'm--', label='High Price')
plt.plot(range(len_h), hist[0], 'k--', label=f'Low {y_label}')
plt.plot(range(len_h), hist[1], 'm--', label=f'High {y_label}')
else:
len_h = len(hist)
min_h, max_h = min(hist), max(hist)
disp = [(hist, minimaIdxs, pmin, 'yo', 'Avg. Support', 'y--'), (hist, maximaIdxs, pmax, 'bo', 'Avg. Resistance', 'b--')]
dispwin = [(hist, minwindows, 'Support', 'g--'), (hist, maxwindows, 'Resistance', 'r--')]
disptrend = [(hist, mintrend, 'Support', 'g--'), (hist, maxtrend, 'Resistance', 'r--')]
plt.plot(range(len_h), hist, 'k--', label='Close Price')
plt.plot(range(len_h), hist, 'k--', label=y_label)
else:
minimaIdxs, pmin, mintrend, minwindows = ([], [], [], []) if hist[0] is None else ret
maximaIdxs, pmax, maxtrend, maxwindows = ([], [], [], []) if hist[1] is None else ret
Expand Down Expand Up @@ -818,9 +821,9 @@ def add_trend(h, trend, lbl, clr, bFirst):
else:
for h, trend, lbl, clr in disptrend:
add_trend(h, trend, lbl, clr, True)
plt.title('Prices with Support/Resistance Trend Lines')
plt.title(title)
plt.xlabel('Date')
plt.ylabel('Price')
plt.ylabel(y_axis_label)
plt.legend()
plt.gca().xaxis.set_major_locator(ticker.MaxNLocator(6))
#plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m'))
Expand Down