-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Unicode with usetex=True and pgf backend #5234
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
Comments
Cc: @pwuertz |
I am pretty sure that it did work at some point, but it's true that usetex true + Unicode cannot be handled by other backends that are using pdflatex. So maybe it should be made clear that this combination of parameters is only possible with xe or lualatex. What puzzles me is the error you are seeing. Your savefig is calling into the qt5 backend instead of pgf. I will try to find out why. |
Why's that? |
AFAIK pdflatex has no support for unicode fonts and generally doesn't know how to handle non-ascii characters. By including inputenc and a few other packages you can add some hardcoded character-to-glyph mappings so you can get away with common language specific characters. But this isn't exactly what you would call "unicode support". |
Ok, this is a bit confusing, and I'm not sure how to wrap this up in the documentation. |
So basically using the |
Not really, the problem is the usetex flag. It isn't really required for backend pgf since all text is processed by tex anyways, so you could just omit it. The GUI will try to process your labels without pdflatex and probably won't be able to interpret more complex latex macros, which looks weird but it won't crash on it. Unfortunately matplotlib internally misuses(?) the usetex flag for some other decisions as well, but if you don't care you can just set usetex=False. |
I am using usetex to get the tick labels in the math font. |
Ah yes, this is one of the things I meant by "other decisions". According to the documentation enabling "usetex" means that the non-latex backends should delegate text rendering to the latex manager and include the result, instead of using the internal matplotlib latex formatter. Unfortunately this flag is also being used for changing the style of the tick labels (putting them in math mode) instead of using a dedicated switch. By the way, I just realized that there is a setting for enabling unicode input encoding in pdflatex/latexmanager. Maybe this is of interest to you? Anyway, if you are not planning on using the GUI and a non-GUI-savefig within the same workflow just go with |
I’m not sure whether this is what I’m facing, because your guys talk about pdflatex while I definitively use xelatex for pgf rendering. But still, needing both pdf export and interactive plots, I’m trying the “registering” method, and when saving a pdf:
|
Oh, indeed the figure is saved (which is the most important point to me), and I also rely on ticks to be in math mode. ;) |
And finally, I was indeed able to work around this by setting |
Just for the record, this is obviously still an issue with 2.0. |
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help! |
The traceback is still happening, but it's a little different now:
This one is because But we go through a lot of trouble to use the right canvas when saving, so it's weird that Qt is drawing here. That's because the QtAgg backend overrides |
AFAICT, `print_figure` is only called in `savefig`, and thus has no relation to backend drawing. We went through a lot of trouble to make `savefig` self-contained, so if this really had any effect, it would be a bug in it instead. But other backends don't do this override and seem to work fine, so these seem superfluous as well. After this change, just opening a window in Qt and using the save button did not seem to break anything, nor did running `savefig` with an interactive window open. I did not test Wx, but given the callers of `print_figure`, I don't see how it could be different. Fixes matplotlib#5234
AFAICT, `print_figure` is only called in `savefig`, and thus has no relation to backend drawing. We went through a lot of trouble to make `savefig` self-contained, so if this really had any effect, it would be a bug in it instead. But other backends don't do this override and seem to work fine, so these seem superfluous as well. After this change, just opening a window in Qt and using the save button did not seem to break anything, nor did running `savefig` with an interactive window open. I did not test Wx, but given the callers of `print_figure`, I don't see how it could be different. Fixes matplotlib#5234
The documentation says that registering the backend should work as well (or better) than
use('pgf')
.This breaks when using unicode because the TeX strings are handled by the default matplotlib texmanager instead of the pgf backend.
If there is no way to disable the standard texmanager when rendering using the pgf backend, the documentation should be changed to make this problem clear.
The text was updated successfully, but these errors were encountered: