Skip to content

Commit

Permalink
Upgraded plot function
Browse files Browse the repository at this point in the history
  • Loading branch information
markvankoningsveld committed Jan 24, 2020
1 parent ac5a862 commit a6e2db1
Showing 1 changed file with 36 additions and 48 deletions.
84 changes: 36 additions & 48 deletions opentisim/agribulk_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -1414,19 +1414,20 @@ def terminal_elements_plot(self, width=0.1, alpha=0.6, fontsize=20):

# generate plot
fig, ax1 = plt.subplots(figsize=(20, 12))
ax1.grid(b=True, which='major', axis='both', zorder=0.5)
ax1.grid(zorder=0, which='major', axis='both')

colors = ['firebrick', 'darksalmon', 'sandybrown', 'darkkhaki', 'palegreen', 'lightseagreen', 'mediumpurple',
'mediumvioletred', 'lightgreen']
offset = 3 * width # - 0.5 * width

ax1.bar([x - offset + 0 * width for x in years], berths, width=width, alpha=alpha, label="Berths", color=colors[0], edgecolor='darkgrey')
ax1.bar([x - offset + 1 * width for x in years], quays, width=width, alpha=alpha, label="Quays", color=colors[1], edgecolor='darkgrey')
ax1.bar([x - offset + 2 * width for x in years], cranes, width=width, alpha=alpha, label="Cranes", color=colors[2], edgecolor='darkgrey')
ax1.bar([x - offset + 3 * width for x in years], conveyors_quay, width=width, alpha=alpha, label="Quay converyors", color=colors[3], edgecolor='darkgrey')
ax1.bar([x - offset + 4 * width for x in years], storages, width=width, alpha=alpha, label="Storages", color=colors[4], edgecolor='darkgrey')
ax1.bar([x - offset + 5 * width for x in years], conveyors_hinterland, width=width, alpha=alpha, label="Hinterland conveyors", color=colors[5], edgecolor='darkgrey')
ax1.bar([x - offset + 6 * width for x in years], unloading_station, width=width, alpha=alpha, label="Unloading stations", color=colors[6], edgecolor='darkgrey')
offset = 3 * width

ax1.bar([x - offset + 0 * width for x in years], berths, zorder=1, width=width, alpha=alpha, label="Berths", color=colors[0], edgecolor='darkgrey')
ax1.bar([x - offset + 1 * width for x in years], quays, zorder=1, width=width, alpha=alpha, label="Quays", color=colors[1], edgecolor='darkgrey')
ax1.bar([x - offset + 2 * width for x in years], cranes, zorder=1, width=width, alpha=alpha, label="Cranes", color=colors[2], edgecolor='darkgrey')
ax1.bar([x - offset + 3 * width for x in years], conveyors_quay, zorder=1, width=width, alpha=alpha, label="Quay converyors", color=colors[3], edgecolor='darkgrey')
ax1.bar([x - offset + 4 * width for x in years], storages, zorder=1, width=width, alpha=alpha, label="Storages", color=colors[4], edgecolor='darkgrey')
ax1.bar([x - offset + 5 * width for x in years], conveyors_hinterland, zorder=1, width=width, alpha=alpha, label="Hinterland conveyors", color=colors[5], edgecolor='darkgrey')
ax1.bar([x - offset + 6 * width for x in years], unloading_station, zorder=1, width=width, alpha=alpha, label="Unloading stations", color=colors[6], edgecolor='darkgrey')

# added vertical lines for mentioning the different phases
# plt.axvline(x=2025.6, color='k', linestyle='--')
# plt.axvline(x=2023.4, color='k', linestyle='--')
Expand Down Expand Up @@ -1461,7 +1462,8 @@ def terminal_elements_plot(self, width=0.1, alpha=0.6, fontsize=20):

# Making a second graph
ax2 = ax1.twinx()
ax2.step(years, demand['demand'].values, label="Demand [t/y]", where='mid', color='blue')
ax2.step(years, demand['demand'].values, zorder=2, label="Demand [t/y]", where='mid', color='blue')

# ax2.step(years, throughputs_online, label="Throughput [t/y]", where='mid', color='#aec7e8')

# added boxes
Expand All @@ -1471,24 +1473,22 @@ def terminal_elements_plot(self, width=0.1, alpha=0.6, fontsize=20):
# ax1.text(0.55, 0.60, 'phase 2', transform=ax1.transAxes, fontsize=18, bbox=props)
# ax1.text(0.82, 0.60, 'phase 3', transform=ax1.transAxes, fontsize=18, bbox=props)

matplotlib.rc('xtick', labelsize=fontsize)
matplotlib.rc('ytick', labelsize=fontsize)

# title and labels
ax1.set_title('Terminal elements online', fontsize=fontsize)

ax1.set_xlabel('Years', fontsize=fontsize)
ax1.set_ylabel('Terminal elements on line [nr]', fontsize=fontsize)
ax2.set_ylabel('Demand/throughput[t/y]', fontsize=fontsize)

# ticks and tick lables
ax1.set_xticks([x for x in years])
ax1.set_xticklabels([int(x) for x in years], fontsize=fontsize)

max_elements = max([max(berths), max(quays), max(cranes),
max(conveyors_quay), max(storages),
max(conveyors_hinterland), max(conveyors_hinterland)])
ax1.set_ylabel('Terminal elements on line [nr]', fontsize=fontsize)
ax1.set_yticks([x for x in range(0, max_elements + 1 + 2, 2)])
ax1.set_yticklabels([int(x) for x in range(0, max_elements + 1 + 2, 2)], fontsize=fontsize)

ax2.set_ylabel('Demand/throughput[t/y]', fontsize=fontsize)

# print legend
fig.legend(loc='lower center', bbox_to_anchor=(0, -.01, .9, 0.7),
fancybox=True, shadow=True, ncol=4)
fig.subplots_adjust(bottom=0.15)
Expand Down Expand Up @@ -1554,7 +1554,7 @@ def terminal_capacity_plot(self, width=0.25, alpha=0.6, fontsize=15):
ax.yaxis.set_tick_params(labelsize=fontsize)
ax.legend(fontsize=fontsize)

def cashflow_plot(self, cash_flows, width=0.3, alpha=0.6, fontsize=15):
def cashflow_plot(self, cash_flows, title='Cash flow plot', width=0.3, alpha=0.6, fontsize=20):
"""Gather data from Terminal elements and combine into a cash flow plot"""

# prepare years, revenue, capex and opex for plotting
Expand All @@ -1579,50 +1579,38 @@ def cashflow_plot(self, cash_flows, width=0.3, alpha=0.6, fontsize=15):
profits_cum = [None] * len(profits)
for index, value in enumerate(profits):
if index == 0:
profits_cum[index] = 0
profits_cum[index] = profits[index]
else:
profits_cum[index] = profits_cum[index - 1] + profits[index]

# generate plot
# generate plot canvas
fig, ax1 = plt.subplots(figsize=(20, 12))
ax1.grid(b=True, which='major', axis='both', zorder=0.5)

colors = ['mediumseagreen', 'firebrick', 'steelblue']
offset = 3 * width # - 0.5 * width

ax1.bar([x - width for x in years], -opex, width=width, alpha=alpha, label="opex", color=colors[0], edgecolor='darkgrey')
ax1.bar(years, -capex, width=width, alpha=alpha, label="capex", color=colors[1], edgecolor='darkgrey')
ax1.bar([x + width for x in years], revenue, width=width, alpha=alpha, label="revenue", color=colors[2], edgecolor='darkgrey')
# print capex, opex and revenue
ax1.bar([x for x in years], -capex, zorder=1, width=width, alpha=alpha, label="capex", color=colors[1], edgecolor='darkgrey')
ax1.bar([x - width for x in years], -opex, zorder=1, width=width, alpha=alpha, label="opex", color=colors[0], edgecolor='darkgrey')
ax1.bar([x + width for x in years], revenue, zorder=1, width=width, alpha=alpha, label="revenue", color=colors[2], edgecolor='darkgrey')

ax1.step(years, profits, label='profits', where='mid')
ax1.step(years, profits_cum, label='profits_cum', where='mid')
# print profits (annual and cumulative)
ax1.step(years, profits, zorder=2, label='profits', where='mid')
ax1.step(years, profits_cum, zorder=2, label='profits_cum', where='mid')

# title and labels
ax1.set_title(title, fontsize=fontsize)
ax1.set_xlabel('Years', fontsize=fontsize)
ax1.set_ylabel('Cashflow [000 M $]', fontsize=fontsize)
ax1.set_title('Cash flow plot', fontsize=fontsize)

# ticks and tick labels
ax1.set_xticks([x for x in years])
ax1.set_xticklabels([int(x) for x in years], fontsize=fontsize)
ax1.yaxis.set_tick_params(labelsize=fontsize)
ax1.legend(fontsize=fontsize)

matplotlib.rc('xtick', labelsize=fontsize)
matplotlib.rc('ytick', labelsize=fontsize)

ax1.set_title('Terminal elements online', fontsize=fontsize)
#
# ax1.set_xlabel('Years', fontsize=fontsize)
# ax1.set_xticks([x for x in years])
# ax1.set_xticklabels([int(x) for x in years], fontsize=fontsize)
#
# max_elements = max([max(berths), max(quays), max(cranes),
# max(conveyors_quay), max(storages),
# max(conveyors_hinterland), max(conveyors_hinterland)])
# ax1.set_ylabel('Terminal elements on line [nr]', fontsize=fontsize)
# ax1.set_yticks([x for x in range(0, max_elements + 1 + 2, 2)])
# ax1.set_yticklabels([int(x) for x in range(0, max_elements + 1 + 2, 2)], fontsize=fontsize)
#
# ax2.set_ylabel('Demand/throughput[t/y]', fontsize=fontsize)
# add grid
ax1.grid(zorder=0, which='major', axis='both')

# print legend
fig.legend(loc='lower center', bbox_to_anchor=(0, -.01, .9, 0.7),
fancybox=True, shadow=True, ncol=5)
fig.subplots_adjust(bottom=0.15)

0 comments on commit a6e2db1

Please sign in to comment.