I am doing a Portfolio analysis. I plot the portfolio returns in a Graph. I could make a figure with 5 years, each years having its own graph, with 2 portfolios in each graph. I have then 5 subplots in a figure. For each subplots I have 2 lines, one for each portfolio, that are the referring to the same for each subplot (see image). So I wanted to have only one legend for the whole figure.
However, with my tries, it always returns this error: 'Figure' object has no attribute 'figlegend'
I have tried 2 possibilities (that are shown on the matplotlib website) to make a figlegend, these are the following:
periods= [0,60,120,180,240,300,360,420,480,540,600,660,720,780,840,900]
fig, axis = plt.subplots(5, 1)
fig.set_size_inches(15, 20)
fig.tight_layout(pad=5.0)
for i in range(5):
p = i+0
axis[i].plot(return_pf_market[periods[p]:periods[p+1]], "darkcyan")
axis[i].plot(return_pf_optimized[periods[p]:periods[p+1]], "lightgreen")
axis[i].set_title(year_str[p])
axis[i].set_xlabel(year_TR[p]+" to "+ year_TR[p+4])
fig.figlegend(['Standard Portfolio', 'Green Portfolio'])
plt.show()
OR
fig, axis = plt.subplots(5, 1)
fig.set_size_inches(15, 20)
fig.tight_layout(pad=5.0)
for i in range(5):
p = i+0
axis[i].plot(return_pf_market[periods[p]:periods[p+1]], "darkcyan", label='Standard Portfolio')
axis[i].plot(return_pf_optimized[periods[p]:periods[p+1]], "lightgreen", label='Green Portfolio')
axis[i].set_title(year_str[p])
axis[i].set_xlabel(year_TR[p]+" to "+ year_TR[p+4])
axis.figlegend()
plt.show()
Do maybe somebody know what is wrong in my code, that makes me get this error ?