You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In working out a simpler version of #4010, I managed to isolate a different issue (at least, externally). In ObsPy, there is a CatchOutput context manager that is used by tests to hide output from scripts that are being tested. It redirects stdout and stderr to files. With matplotlib 1.3.1, plots turned out fine using this approach.
With matplotlib 1.4.2, something gets messed up somewhere and text is no longer placed correctly.
I have put together a self-contained example including the context manager. It saves what should be the same image twice as x1.png and x2.png, but the second one appears as above. Some things to note:
It works correctly with the TkAgg backend instead of the Agg backend.
It works correctly if both plots are within the same CatchOutput context.
Quizzically, there are several CatchOutput contexts in the ObsPy tests, but only one pair seem to trigger the bug. Yet this example seems to always trigger the problem and it's much simpler.
Now, superficially, the CatchOutput context makes sense to me, and though it is a bit of black magic, it did seem to work alright against matplotlib 1.3.1.
The text was updated successfully, but these errors were encountered:
Here's what is happening: CatchOutput creates temporary files to redirect stdout and stderr to. Let's say they are assigned the values 3 and 4. Those fds are cloned into stdout and stderr (thus redirecting), and then they are closed on lines 55/56. This "recycles" those file descriptors to be used again. When the matplotlib code runs, it opens the font using an fd of "3". Then when it's done, the font file is closed on line 81. (Note the code says is it closing the temporary file, but "3" now refers to the font file. There is the error). When the second plot is run, matplotlib reuses the handle to the font file, not realizing that the file has actually been closed out from underneath it. This means it thinks the width of every character is 0, hence the rendering bug you're seeing.
TL;DR: The bug is due to incorrect handling of low-level file handles, and there's not much matplotlib can do to protect against that. I'm calling it not an mpl bug, but feel free to reopen if you have further evidence otherwise.
In working out a simpler version of #4010, I managed to isolate a different issue (at least, externally). In ObsPy, there is a
CatchOutput
context manager that is used by tests to hide output from scripts that are being tested. It redirectsstdout
andstderr
to files. With matplotlib 1.3.1, plots turned out fine using this approach.With matplotlib 1.4.2, something gets messed up somewhere and text is no longer placed correctly.
I have put together a self-contained example including the context manager. It saves what should be the same image twice as
x1.png
andx2.png
, but the second one appears as above. Some things to note:TkAgg
backend instead of theAgg
backend.CatchOutput
context.CatchOutput
contexts in the ObsPy tests, but only one pair seem to trigger the bug. Yet this example seems to always trigger the problem and it's much simpler.Now, superficially, the
CatchOutput
context makes sense to me, and though it is a bit of black magic, it did seem to work alright against matplotlib 1.3.1.The text was updated successfully, but these errors were encountered: