Adobe
Adobe

Reputation: 13467

matplotlib: how do I easily fit the plot to the canvas

May be that is a simple question - but I tried to solve it several times - and just can't make it work. My problem is that - my plot is larger than the canvas: Plot is larger then the canvas!

Is there a way to make plot fit to the canvas - without changing the canvas size?

Here's the code that I use to make a plot (thanks to the Louis):

da = plt.figure()
l1 = da.add_subplot(111).plot(dummyZ, delta_a, "k-")
da.add_subplot(111).set_xlabel(r"$z/L$")
da.add_subplot(111).set_ylabel(r"$\delta a(z)$")
da.add_subplot(111).grid(True)
da.savefig("da.png")

And here's the preambule:

import matplotlib.pyplot as plt
plt.rcParams['font.size']=18

Edit:

That's what I'm using now:

da = plt.figure()
l1 = da.add_subplot(111).plot(dummyZ, delta_a, "k-")
da.add_subplot(111).set_xlabel(r"$z/L$")
da.add_subplot(111).set_ylabel(r"$\delta a(z)$")
da.add_subplot(111).grid(True)
da.subplots_adjust(left=0.2, bottom=0.15) # !!!
da.savefig("da.png")

Upvotes: 3

Views: 1859

Answers (1)

Louis
Louis

Reputation: 2890

If I understand correctly the question, you want more room on the left to get the scale title ?

This is to be done with

fig.subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=None, hspace=None)

I had it with a simple

subplots_adjust(top=0.8)

to adjust the top of one of my draws.

Hope this could help.

Upvotes: 2

Related Questions