Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Bug]: EPS savefig messed up by 'figure.autolayout' rcParam on 3.5.0 #21930

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
alex180500 opened this issue Dec 11, 2021 · 8 comments · Fixed by #22732
Closed

[Bug]: EPS savefig messed up by 'figure.autolayout' rcParam on 3.5.0 #21930

alex180500 opened this issue Dec 11, 2021 · 8 comments · Fixed by #22732

Comments

@alex180500
Copy link

Bug summary

Setting 'figure.autolayout' to 'True' removes most of the EPS savefig.

Code for reproduction

import matplotlib.pyplot as plt

plt.rcParams['figure.autolayout'] = 'True'

plt.plot([1, 2, 3], [1, 2, 3], 'o-')
plt.title(r'$\sum_{i=0}^{\infty} x_i$ just a test')
plt.savefig('test2.eps', format='eps')

Actual outcome

Actual image after being exported from gimp (300dpi)

actual

This is the EPS file:
https://we.tl/t-ka6aoUGxKm

Expected outcome

Expect the image in ".eps" file like this.

expected

This is the EPS file:
https://we.tl/t-Q7WBPMwDcy

Additional information

I found this bug by an accident while using a custom ".mplstyle" on Matplotlib 3.5.0
Seems like this rcParam ['figure.autolayout'] = 'True' destroys about 2/3 of the eps file.
plt.tightlayout() seem to not affect the result, the bug happens only with this rcParam on the latest matplotlib version.

import matplotlib.pyplot as plt

plt.plot([1, 2, 3], [1, 2, 3], 'o-')
plt.title(r'$\sum_{i=0}^{\infty} x_i$ just a test')
plt.savefig('test2.eps', format='eps')

This is the code for the expected outcome.

Operating system

Windows

Matplotlib Version

Bug present only on 3.5.0

Matplotlib Backend

Qt5Agg

Python version

Tested with 3.10 and 3.9

Jupyter version

No response

Installation

conda

@jklymak
Copy link
Member

jklymak commented Dec 11, 2021

I can confirm this, but I don't understand it. If you instead do

import matplotlib.pyplot as plt

# plt.rcParams['figure.autolayout'] = 'True'
 
plt.figure(layout='tight')
plt.plot([1, 2, 3], [1, 2, 3], 'o-')
plt.title(r'$\sum_{i=0}^{\infty} x_i$ just a test')
plt.savefig('test2.eps', format='eps')

it works fine.

If you use the rcParam and save as PDF it works fine. So I'm not sure why the ps backend is doing something different.

@jklymak
Copy link
Member

jklymak commented Dec 11, 2021

Same behaviour with plt.rcParams['figure.constrained_layout.use'] = True.

@alex180500
Copy link
Author

Still not fixed in 3.5.1

@jklymak
Copy link
Member

jklymak commented Dec 13, 2021

someone will have to dig into it before it gets fixed.

@QuLogic
Copy link
Member

QuLogic commented Dec 16, 2021

plt.figure(layout='tight')

I'm not sure how you got this to work, I see no appreciable difference in the file between the rcParam vs the parameter (i.e., both are broken).

@jklymak
Copy link
Member

jklymak commented Dec 16, 2021

Oh good, I must have been mixing up files somehow. Glad that it is consistent between the ways to set tight_layout...

@alex180500
Copy link
Author

I've just tested it out and...

plt.figure(layout='tight')

gives a broken result like with the rcParam.

But

plt.tight_layout()

does not. 🤔

@shmilee
Copy link

shmilee commented Apr 3, 2022

I've just tested it out and...

plt.figure(layout='tight')

gives a broken result like with the rcParam.

But

plt.tight_layout()

does not. thinking

Same here with version 3.5.1 in archlinux.
And some lines are lost at the end of broken eps, like gsave, grestore things:

 FontName currentdict end definefont pop
 end
 %%EndProlog
 mpldict begin
 68.4 288 translate
 475.2 216 0 0 clipbox
-gsave
-0 0 m
-475.2 0 l
-475.2 216 l
-0 216 l
-cl
-1.000 setgray
-fill
-grestore
-
-................ more lines
-
-gsave
-
-384.960000 50.672828 translate
-0.000000 rotate
-0.000000 0 m /T glyphshow
-grestore

 end
 showpage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants