Skip to content

Commit 7d8bec2

Browse files
committed
Map/Reduce for the total number of rows in the graph/subplots
1 parent f58ac53 commit 7d8bec2

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

040_ticker_plots

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def load_df(path, ticker, date_field):
2323
df = pd.read_csv(file_path, parse_dates=[date_field], date_parser=dateparse)
2424
return df;
2525

26-
def build_plot(cur_dict, ticker, shared_axis):
26+
def build_plot(cur_dict, ticker, num_rows_num_cols_tuple, shared_axis):
2727
current_df = load_df(cur_dict['path_prefixes'], ticker, cur_dict['date_field_name'])
2828
ax = plt.subplot2grid(num_rows_num_cols_tuple, (cur_dict['row_position'], 0), rowspan=cur_dict['rowspan'])
2929
if (shared_axis):
@@ -87,15 +87,20 @@ series_dicts = {
8787
'closing_price_data': closing_price_dict
8888
}
8989

90-
num_rows_num_cols_tuple = (7,1)
90+
def get_total_graph_rows(dictionaries):
91+
available_series = dictionaries.keys()
92+
rows_each = map(lambda curr_series: dictionaries[curr_series]['rowspan'], available_series)
93+
return reduce(lambda x, y: x+y, rows_each)
9194

9295
def get_plt(dicts, ticker):
96+
total_rows = get_total_graph_rows(dicts)
97+
num_rows_num_cols_tuple = (total_rows,1)
9398
plt.suptitle(ticker + ' ticker')
94-
ax_eps = build_plot(dicts['eps_data'], ticker, None)
95-
ax_peg = build_plot(dicts['peg_data'], ticker, ax_eps)
96-
ax_pe_median = build_plot(dicts['pe_median_data'], ticker, ax_eps)
97-
ax_outstanding_shares = build_plot(dicts['outstanding_shares_data'], ticker, ax_eps)
98-
ax_closing_price = build_plot(dicts['closing_price_data'], ticker, ax_eps)
99+
ax_eps = build_plot(dicts['eps_data'], ticker, num_rows_num_cols_tuple, None)
100+
ax_peg = build_plot(dicts['peg_data'], ticker, num_rows_num_cols_tuple, ax_eps)
101+
ax_pe_median = build_plot(dicts['pe_median_data'], ticker, num_rows_num_cols_tuple, ax_eps)
102+
ax_outstanding_shares = build_plot(dicts['outstanding_shares_data'], ticker, num_rows_num_cols_tuple, ax_eps)
103+
ax_closing_price = build_plot(dicts['closing_price_data'], ticker, num_rows_num_cols_tuple, ax_eps)
99104

100105
plt.xlabel('Date')
101106
plt.xticks(rotation=45)

0 commit comments

Comments
 (0)