6

Try to do a graph using python matplotlib: but keep getting the following waring message:

"UserWaring: tight_layout: falling back to Agg renderer  warnings.warn("tight_layout: falling back to Agg renderer")

My code is below:

plt.legend(loc='upper left',prop = {'size':7},bbox_to_anchor=(1,1))
plt.tight_layout(pad=7)
plt.xlabel ('Build')
plt.ylabel ('Time/Sec')
plt.title ('Performance Test')
plt.grid()
plt.show()

graph from the code How to fix that warning message?

1
  • Can you please use the code format (ctrl + k) and give a proper dataset to reproduce the warning ? Commented May 18, 2016 at 20:37

1 Answer 1

13

Are you using MacOSX? It seems to be a known and open issue

https://github.com/matplotlib/matplotlib/issues/1852

I will suggest to reorganize the code such that you will use Figure instead of pyplot. You can get the Figure from plt.figure() method. Then, on the Figure instance call set_tight_layout(True). Try this example code:

import matplotlib
matplotlib.use('pdf')
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
fig.set_tight_layout(True)
fig.savefig('asd.pdf')  # No warning now

As a side note, have a look at matplotlib documentation

tight_layout() can take keyword arguments of pad, w_pad and h_pad. These control the extra padding around the figure border and between subplots. The pads are specified in fraction of fontsize.

http://matplotlib.org/users/tight_layout_guide.html

This suggest that your code

plt.tight_layout(pad=7)

is wrong, as the value of pad should be between 0 and 1.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. Using fig.set_tight_layout(True) instead of fig.tight_layout() solved the issue for me, even if I use windows and not MacOSX.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.