0

I'm using pandas to manipulate some data stored in variable x. So doing

x.plot(figsize=(10,6))

will produce the chart that is on the top part of the image I shared.

Then I use subplots with the same figsize, and the result is the bottom part of the image.

fig, axes = plt.subplots(2,2, figsize=(10,6))
axes = axes.ravel()
dfs = dict()
for i, ax in enumerate(axes):
    y = backtest_up(x)[['v1', 'v2']]
    ax.plot(y)

Why are the plots different in size if the both have the same figsize value?

enter image description here

Yuca
  • 6,010
  • 3
  • 22
  • 42
  • If you draw one plot on a sheet of paper and draw 4 plots on a sheet of the same size, each of the four plots necessarily need to be smaller (roughly half in length, quarter in area) to fit to that sheet. – ImportanceOfBeingErnest Aug 09 '18 at 14:42
  • Agree, the issue here is that the 'white canvas' used to display the single plot is smaller than the 'white canvas' used to display the smaller plots. I was hoping that setting the same figsize would make the 'white canvas' have the same size – Yuca Aug 09 '18 at 14:52

1 Answers1

1

In matplotlib, figsize sets the size of the whole figure.

In your first example, there is just one graph so it will take the whole figure. In the second example, there is four graph so each will take one quarter of the figure.

But the size of the 4 graphs together is the same than the single graph.

Cendre
  • 114
  • 8
  • hmm. this doesn't make a lot of sense to me. For example if I use plt.tight_layout after the subplots, the disparity is even more notorious – Yuca Aug 09 '18 at 14:35
  • https://ibb.co/iPbCqp On this image I put the figsize in red, is it clearer ? – Cendre Aug 09 '18 at 14:51
  • much clearer! and that's exactly my point, your figsizes match, and mines doesn't although I set the figsize param on both. So how should I use the figsize parameter to replicate your results? – Yuca Aug 09 '18 at 14:54
  • I'm not sure, it's not obvious on your screenshot that it doesn't match, you have this weird thing figsize=figsize=(10,6) in your code. – Cendre Aug 09 '18 at 15:04
  • fixed the figsize typo. From the screenshot you can see that the bottom plot has more width, that's what's bothering me – Yuca Aug 09 '18 at 15:08
  • If you run the same minimal example that I did, is it different? – Cendre Aug 09 '18 at 15:18
  • it is, I restarted my kernel to avoid random noise and the subplot has less width than the regular plot – Yuca Aug 09 '18 at 15:21
  • https://ibb.co/e8gn6U – Yuca Aug 09 '18 at 15:29
  • %matplotlib inline with this also? That is the only difference in our code – Cendre Aug 09 '18 at 15:39
  • I was not using matlplotlib inline, I added it to my code and got the same results – Yuca Aug 09 '18 at 15:46
  • Great ! I don't know why it makes a difference, if you find out let me know – Cendre Aug 09 '18 at 15:59
  • Sorry, when I said same results I meant that nothing changed! – Yuca Aug 09 '18 at 16:00