set_size_inches not working with matplotlib figure

Viewed 556

I have the following snippet of code, the first block, that creates a scatter plot and saves it to a file. But no matter what size I specify with set_size_inches it still saves this small plot to the file. I think maybe I can't specify the figure size after it's already been plotted?

I'm confused because essentially the same code, second snippet below, works just fine.

Any ideas?

Thanks!

.

None working snippet:

# Attach the plotter to the strategy.
plt = plotter.StrategyPlotter(myStrategy)

# Plot the simple returns on each bar.
plt.getOrCreateSubplot("returns").addDataSeries("Simple returns", retAnalyzer.getReturns())

# Run the strategy.
myStrategy.run()

fig = matplotlib.pyplot.gcf()
fig.set_size_inches(18.5, 10.5, forward=True)

results = {}
results['final_value'] = myStrategy.getResult()
results['cum_returns'] = retAnalyzer.getCumulativeReturns()[-1] * 100

plt.savePlot('./plots/%s_%s.png' % ( str(int(results['cum_returns'])), name ))

Working snippet:

df.plot.scatter(x='date',
                y='close',
                c='color',
                )

fig = matplotlib.pyplot.gcf()
fig.set_size_inches(18.5, 10.5, forward=True)


plt.savefig('./plots/%s.png' % name)


plt.close(fig)
0 Answers
Related