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
Fix for ylabel title in example tex_unicode_demo.py #6832
Conversation
Is the bug in the example and not in the other place?
|
Apparently, there's a separate bug where the gallery image is chopped. |
@Kojoley This bug report is referring to the label for the y axis, where |
I have posted a rendered image of this example with matplotlib v1.4.3 and it looks right to me. That's why I think it is not a bug in the example, but in matplotlib itself. |
@Kojoley The bug report was made with matplotlib v1.5.1. But I get the same wrong image with matplotlib v1.4.3. Tested with Python distribution Anaconda, environment
Who is responsible for parsing the Unicode escape sequence The temporary file for TeX contains the degree symbol in encoding UTF-8, The bug of the example is, that the escape sequence is put in a raw string (r'') |
TLDR: this is the correct fix. Can you also remove the line-break @hoiqs your analysis seems correct, which leads to the question of how did the 1.4.3 docs come out right, which lead me down a fun rabbit hole. It looks like I built the 1.4.3 docs 2015-02-16 but I can not sort out how to get the version of latex (or python) I used out of the files. If I re-run this from 1.4.3 on my current system with 3.5 I get This is what is getting handed off to latex (pulled from \documentclass{article}
\usepackage{type1cm}
\renewcommand{\rmdefault}{pnc}
\usepackage{helvet}
\usepackage{courier}
\usepackage{textcomp}
\usepackage{ucs}
\usepackage[utf8x]{inputenc}
\usepackage[papersize={72in,72in},body={70in,70in},margin={1in,1in}]{geometry}
\pagestyle{empty}
\begin{document}
\fontsize{16.000000}{20.000000}{\sffamily \textit{Velocity (\u00B0/sec)}}
\end{document}
However, if I run mpl 1.5.1 with python2.7 \documentclass{article}
\usepackage{type1cm}
\renewcommand{\rmdefault}{pnc}
\usepackage{helvet}
\usepackage{courier}
\usepackage{textcomp}
\usepackage{ucs}
\usepackage[utf8x]{inputenc}
\usepackage[papersize={72in,72in},body={70in,70in},margin={1in,1in}]{geometry}
\pagestyle{empty}
\begin{document}
\fontsize{16.000000}{20.000000}{\sffamily \textit{Velocity (°/sec)}}
\end{document}
Note that the title is back on one line, the degree symbol is fixed, and it appears an unicode in the tex file. So note: 22:30 $ python2
Python 2.7.12 (default, Jun 28 2016, 08:31:05)
[GCC 6.1.1 20160602] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> r'\textit{Velocity (\u00B0/sec)}'
'\\textit{Velocity (\\u00B0/sec)}'
>>> '\\textit{Velocity (\u00B0/sec)}'
'\\textit{Velocity (\\u00B0/sec)}'
>>> from __future__ import unicode_literals
>>> r'\textit{Velocity (\u00B0/sec)}'
u'\\textit{Velocity (\xb0/sec)}'
>>> '\\textit{Velocity (\u00B0/sec)}'
u'\\textit{Velocity (\xb0/sec)}'
>>> vs 22:29 $ python
Python 3.5.2 (default, Jun 28 2016, 08:46:01)
[GCC 6.1.1 20160602] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> r'\textit{Velocity (\u00B0/sec)}'
'\\textit{Velocity (\\u00B0/sec)}'
>>> '\\textit{Velocity (\u00B0/sec)}'
'\\textit{Velocity (°/sec)}'
>>> Tracing back the history of this line it went through a bunch of different ways of specifying that it was a unicode string. This is the documented behavior https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals |
Turns out we have this documented in our dev guide: http://matplotlib.org/devel/portable_code.html#the-dreaded-u-escapes |
quotes are changed to single quotes to follow the quote symbol of the other strings.
@tacaswell Thanks for your analysis, indeed the example works with Python 2.7, where the raw string interprets the As requested I have changed the line break in the title following the line break in |
DOC: Fix for ylabel title in example tex_unicode_demo.py Issue with py2/p3 unicode escape
backported to v1.5.2-doc as 7074991 |
@hoiqs Thanks! |
The example is about using Unicode characters with TeX. However, the example uses a raw string type for the Unicode escape sequence:
That means that the escape sequence appears literally instead of the degree sign.
Proposed fix is a normal string with doubling of the backslash for the TeX macro
\textit
: