0

I'm trying to place an Axes within a Figure so that the Axes has substantial margins within the Figure.

When I render it with plt.savefig, it works fine:

fig = plt.figure(figsize=(4, 4))
ax1 = fig.add_axes([.3, .3, .1, .1])
ax2 = fig.add_axes([.6, .6, .1, .1])
plt.savefig("my figure", facecolor="grey")

enter image description here

But when I render it with plt.show, it crops the Figure to any contained Axes:

fig = plt.figure(figsize=(4, 4), facecolor="grey")
ax1 = fig.add_axes([.3, .3, .1, .1])
ax2 = fig.add_axes([.6, .6, .1, .1])
plt.show()

enter image description here

How do I stop plt.show from cropping the Figure, and instead show the true size of the Figure, like plt.savefig does?

Denziloe
  • 7,473
  • 3
  • 24
  • 34
  • 1
    1. You save the file with `figsize=(10, 10)` and you show the image with `figsize=(4, 4)`, so there is at least one difference in size coming from. 2. Are only running the code you posted? Because this is not happening for me... – funie200 Jun 07 '19 at 10:16
  • Good catch, apologies -- that was just a typo in the source though, which I've fixed. What behaviour are you seeing exactly? Is `plt.show` not cropping? – Denziloe Jun 07 '19 at 10:37
  • `plt.show` is not cropping on my system. Python `3.6.8` and matplotlib `3.1.0`. Does changing `figsize` affect the output? – Vishnu Dasu Jun 07 '19 at 10:40
  • matplotlib `2.2.3`, Python `3.7.0`. Within a Jupyter Notebook if that makes a difference. I'm surprised matplotlib is so old; I'll update and see if that resolves this. – Denziloe Jun 07 '19 at 10:48
  • @VishnuDasu I'm now updated to matplotlib `3.1.0` -- the problem persists. Changing the figure size simply produces a scaled up version of the figure I posted. – Denziloe Jun 07 '19 at 11:05
  • 1
    @Denziloe I get the same output as you did within a Jupyter Notebook. The solution in the question marked as duplicate seems to work, have a look. – Vishnu Dasu Jun 07 '19 at 11:40

0 Answers0