From 823a5ba05a2f90a0ddb50c027c6eb5a17bdd758c Mon Sep 17 00:00:00 2001 From: CelestialCrafter Date: Sat, 23 Sep 2023 19:43:51 -0500 Subject: [PATCH] added color api made all the plots use color api --- plots/bollinger_bands.py | 11 ++++++----- plots/bot_net_worth.py | 5 +++-- plots/colors.py | 14 ++++++++++++++ plots/macd.py | 9 +++++---- plots/rsi.py | 7 ++++--- 5 files changed, 32 insertions(+), 14 deletions(-) create mode 100644 plots/colors.py diff --git a/plots/bollinger_bands.py b/plots/bollinger_bands.py index 40cda19..2e723bc 100755 --- a/plots/bollinger_bands.py +++ b/plots/bollinger_bands.py @@ -1,6 +1,7 @@ import numpy as np import matplotlib.pyplot as plt from algorithms.bollinger_bands import algorithm as boillinger_bands +import colors def plot(prices): upper_band, lower_band, middle_band = boillinger_bands(prices) @@ -11,14 +12,14 @@ def plot(prices): plt.fill_between(indicies, upper_band, lower_band, color='grey', alpha=0.3) # Price/SMA - plt.plot(indicies, sliced_prices, color='plum') - plt.plot(indicies, middle_band, color='mediumpurple') + plt.plot(indicies, sliced_prices, color=colors.mainline()) + plt.plot(indicies, middle_band, color=colors.secondaryline()) # Buy/Sell Signals upper_condition = sliced_prices >= upper_band lower_condition = sliced_prices <= lower_band - plt.scatter(indicies[upper_condition], sliced_prices[upper_condition], color='lightcoral') - plt.scatter(indicies[lower_condition], sliced_prices[lower_condition], color='darkturquoise') - + plt.scatter(indicies[upper_condition], sliced_prices[upper_condition], color=colors.upper()) + plt.scatter(indicies[lower_condition], sliced_prices[lower_condition], color=colors.lower()) + return plt diff --git a/plots/bot_net_worth.py b/plots/bot_net_worth.py index 13b2b80..ca12f08 100644 --- a/plots/bot_net_worth.py +++ b/plots/bot_net_worth.py @@ -1,9 +1,10 @@ import numpy as np import matplotlib.pyplot as plt +import colors def plot(bot_profit): bot_profit = np.array(bot_profit) indicies = np.arange(0, bot_profit.shape[0]) * 5 - plt.plot(indicies, bot_profit, color='lightcoral') + plt.plot(indicies, bot_profit, color=colors.upper()) - return plt \ No newline at end of file + return plt diff --git a/plots/colors.py b/plots/colors.py new file mode 100644 index 0000000..668492d --- /dev/null +++ b/plots/colors.py @@ -0,0 +1,14 @@ +def mainline(): + return 'plum' + +def secondaryline(): + return 'mediumpurple' + +def upper(): + return 'lightcoral' + +def lower(): + return 'darkturquoise' + +def inner(): + return 'grey' diff --git a/plots/macd.py b/plots/macd.py index 0d33e75..7081027 100755 --- a/plots/macd.py +++ b/plots/macd.py @@ -1,6 +1,7 @@ import numpy as np import matplotlib.pyplot as plt from algorithms.macd import algorithm as macd +import colors def plot(prices): macd_line, signal_line = macd(prices) @@ -9,10 +10,10 @@ def plot(prices): upper_condition = macd_line > signal_line lower_condition = macd_line < signal_line - plt.scatter(indicies[upper_condition], signal_line[upper_condition], color='darkturquoise') - plt.scatter(indicies[lower_condition], signal_line[lower_condition], color='lightcoral') + plt.scatter(indicies[upper_condition], signal_line[upper_condition], color=colors.lower()) + plt.scatter(indicies[lower_condition], signal_line[lower_condition], color=colors.upper()) - plt.plot(signal_line, color='plum') - plt.plot(macd_line, color='mediumpurple') + plt.plot(signal_line, color=colors.mainline()) + plt.plot(macd_line, color=colors.secondaryline()) return plt diff --git a/plots/rsi.py b/plots/rsi.py index 6ebc766..daeba5b 100755 --- a/plots/rsi.py +++ b/plots/rsi.py @@ -1,19 +1,20 @@ import numpy as np import matplotlib.pyplot as plt from algorithms.rsi import algorithm as rsi +import colors def plot(prices): rsi_data = rsi(prices) rsi_indicies = np.arange(0, rsi_data.shape[0]) - plt.plot(rsi_indicies, rsi_data, color='plum') + plt.plot(rsi_indicies, rsi_data, color=colors.mainline()) # Thresholds rsi_upper = np.full(rsi_data.shape, 70) rsi_lower = np.full(rsi_data.shape, 30) plt.fill_between(rsi_indicies, rsi_upper, rsi_lower, color='grey', alpha=0.3) - plt.plot(rsi_indicies, rsi_upper, linestyle='dashed', color='lightcoral') - plt.plot(rsi_indicies, rsi_lower, linestyle='dashed', color='darkturquoise') + plt.plot(rsi_indicies, rsi_upper, linestyle='dashed', color=colors.upper()) + plt.plot(rsi_indicies, rsi_lower, linestyle='dashed', color=colors.lower()) return plt