Note that there are some explanatory texts on larger screens.

plurals
  1. POpad_inches=0 and bbox_inches="tight" makes the plot smaller than declared figsize
    text
    copied!<p>I am producing a publication-quality plot to be embedded in latex and I would like to be very precise in terms of sizes and fonts (so that fonts are of the same size in the article as in the plot). To prevent the plot from scaling in latex I would like to have it exact size, but I cannot. Here is my code:</p> <pre><code>import matplotlib.pyplot as plt from matplotlib import rc, rcParams from numpy import sin rc('text', usetex=True) rc('font', family='serif', serif='Computer Modern Roman', size=8) rc('legend', fontsize=10) width_in = 5 fig = plt.figure(1, figsize=(width_in, 2)) ax = fig.add_subplot(111) ax.plot(range(0,100), sin(range(0,100))) fig.tight_layout() fig.savefig('test.eps', bbox_inches='tight', pad_inches=0) plt.close() </code></pre> <p>The problem is with bbox_inches='tight' and pad_inches=0. Adding those options makes my plot 4.76 inches wide instead of declared 5 inches. But I want them to save space. So how to solve it?</p> <p>Edit: Well, the answers suggest to remove <code>bbox_inches='tight'</code> and <code>pad_inches=0</code> and use just the <code>tight_layout()</code>. Then the images is of right size, however it has still some white padding around. I can remove it with <code>fig.tight_layout(pad=0)</code>, but then the figure title it moved inside the box, which looks ugly. On the other hand I can use <code>tight_layout(rect=[...])</code> and obtain the desired result, but it is a manual work to get the numbers right - I don't like it. Thus, currently I don't see any easy and general solution to my problem. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload