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

Skip to content

Some LaTeX symbols not scaling with increased figure sizes. #11901

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
oliversheridanmethven opened this issue Aug 20, 2018 · 2 comments
Closed

Comments

@oliversheridanmethven
Copy link

I have noticed that when I increase the figure size to some very large sizes (for use on a very large and non-primary monitor) that not all the LaTeX symbols are being scaled correctly.

e.g.

When I use a very small figure size (which fits within the default monitor size) everything seems to be fine:

enter image description here

However, when I increase the figure sizes not all the symbols scale.

the good
enter image description here

the bad
enter image description here

and the ugly
enter image description here

Some of the problem symbols include int, frac, sqrt (display style), and scaling parentheses.

Why mention default Ubuntu display?

I know Matplotlib has some issues with canvases which are bigger than the default window size, e.g. Initial plot window ignoring rcParams figure.figsize #10555, and Add scrollbars when needed to preserve specified figure size #7338)

The code:

Using a virtual environment python 2.7.12 and matplotlib 2.2.3 and TkAgg backend on Ubuntu 16.04. (Not exactly MWE but close enough I hope).

import matplotlib as mpl
plt_style = 1 # Toggle this to see the difference
if plt_style == 0:  
    rc_fonts = {
        "text.usetex": True,
        "font.size": 30,
        'mathtext.default': 'regular',
        'axes.titlesize': 33,
        "axes.labelsize": 33,
        "legend.fontsize": 30,
        "xtick.labelsize": 30,
        "ytick.labelsize": 30,
        'figure.titlesize': 33,
        'figure.figsize': (15,9.3),
        'text.latex.preamble': [r'\usepackage{amsmath,amssymb,bm,physics,lmodern}'],
        "font.family": "serif",
        "font.serif": "computer modern roman",
        }
elif plt_style == 1:
    rc_fonts = {
        "text.usetex": True,
        "font.size": 50,
        'mathtext.default': 'regular',
        'axes.titlesize': 55,
        "axes.labelsize": 55,
        "legend.fontsize": 50,
        "xtick.labelsize": 50,
        "ytick.labelsize": 50,
        'figure.titlesize': 55,
        'figure.figsize': (25, 16.5),  # 15, 9.3
        'text.latex.preamble': [r'\usepackage{amsmath,amssymb,bm,fontenc,physics,lmodern,nicefrac}'],
        "font.family": "serif",
        "font.serif": "computer modern roman",
    }
elif plt_style == 2:
    rc_fonts = {
        "text.usetex": True,
        "font.size": 15,
        'mathtext.default': 'regular',
        'axes.titlesize': 16,
        "axes.labelsize": 16,
        "legend.fontsize": 15,
        "xtick.labelsize": 15,
        "ytick.labelsize": 15,
        'figure.titlesize': 16,
        'figure.figsize': (7.5,4.65),
        'text.latex.preamble': [r'\usepackage{amsmath,amssymb,bm,physics,lmodern}'],
        "font.family": "serif",
        "font.serif": "computer modern roman",
        }
mpl.rcParams.update(rc_fonts)
import matplotlib.pylab as plt
import pandas as pd
import numpy as np

# e.g. An example plot

x = np.linspace(-3, 3, 1000)
y1 = np.exp(-0.5*x**2)/np.sqrt(2.0*np.pi)
y2 = np.sin(x)**2.0*np.exp(-0.5*x**2)/np.sqrt(2.0*np.pi)
plt.clf()  # I usually clear the current figure.
plt.plot(x, y1, 'k-', label='Standard Gaussian')
plt.plot(x, y2, 'r-', label='Modified Gaussian')
plt.legend(loc='upper left', frameon=False)
plt.title('Gaussian functions', y=1.02)  # A small vertical offset is usually nice.
plt.xlabel(r'$x$')
plt.ylabel(r'$f(x)$')
plt.ylim((0, 0.5))
plt.xlim((min(x), max(x)))
plt.gca().text(0.98, 0.98, r'$\displaystyle\int_\mathbb{R}^{} \sqrt{\dfrac{1}{\sqrt{2\pi\sigma}} \exp(-\dfrac{x^2}{2\sigma^2})} \dd{x} = 1 $', transform=plt.gca().transAxes, horizontalalignment='right', verticalalignment='top')
# plt.savefig('figures/gaussian_{}.pdf'.format(plt_style), format='pdf', bbox_inches='tight', transparent=True)
@tacaswell tacaswell added this to the v3.1 milestone Aug 23, 2018
@tacaswell
Copy link
Member

In one of the worst maintainer responses possible, I don't think this is a bug in Matplotilb.

You are using latex to do the font rendering which means Matplotlib is not involved in the text rendering at all, we just use what latex produces. You can find the temporary files we use for this in ~/.cache/matplotlib/tex.cache (we cache things for speed, the hash is based on the contents, check tex_manager for details). Digging out the tex file used the miss behaving text you find

\documentclass{article}
\usepackage{type1cm}



\usepackage{textcomp}

\usepackage[utf8]{inputenc}
\usepackage{amsmath,amssymb,bm,fontenc,physics,lmodern,nicefrac}
\usepackage[papersize={72in,72in},body={70in,70in},margin={1in,1in}]{geometry}
\pagestyle{empty}
\begin{document}
\fontsize{50.000000}{62.500000}{\rmfamily $\displaystyle\int_\mathbb{R}^{} \sqrt{\dfrac{1}{\sqrt{2\pi\sigma}} \exp(-\dfrac{x^2}{2\sigma^2})} \dd{x} = 1 $}
\end{document}

which if you render with pdflatex you get the same issues.

If I comment out your preamble it renders correctly (and you have different preambles in the different cases).

I am going to close this as I don't think there is anything we can do on the Matplotlib side, but please ping to re-open if we are calling latex badly or should tweak our template.

@tacaswell tacaswell removed this from the v3.1 milestone Aug 23, 2018
@oliversheridanmethven
Copy link
Author

A fix was to use fixcmex as outlined in this answer.

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

No branches or pull requests

2 participants