Skip to content
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

Usetex demo is slow on windows #15802

Open
Echeban opened this issue Dec 1, 2019 · 10 comments
Open

Usetex demo is slow on windows #15802

Echeban opened this issue Dec 1, 2019 · 10 comments
Labels
keep Items to be ignored by the “Stale” Github Action Performance topic: text/usetex

Comments

@Echeban
Copy link

Echeban commented Dec 1, 2019

Bug report

Bug summary

I just downloaded usetex_demo.html
from
https://matplotlib.org/3.1.1/gallery/text_labels_and_annotations/usetex_demo.html

I did not modify it, nothing at all. I just try to run it.

Code for reproduction

exactly what I downloaded.

Actual outcome

The canvas/figure appears on a window as usual when invoking plt.show() but it has no content and it is unresponsive. I have to kill it, which reports the problem to Microsoft.

Expected outcome

A figure similar to that shown on the documentation.

Matplotlib version

  • Operating system: Windows 10, 64
  • Matplotlib version:
  • Matplotlib backend (print(matplotlib.get_backend())): TkAgg
  • Python version: 3.7
  • Jupyter version (if applicable): N/A
  • Other libraries: numpy #as included in the demo. I load the code into VSCode, then hit F5. My VSCode installation is working fine. Everything runs inside a venv. Typical setup. All packages updated using pip. I installed everything from pip
    pip freeze:
    altgraph==0.16.1
    astroid==2.3.2
    cffi==1.13.2
    colorama==0.4.1
    cryptography==2.8
    cx-Freeze==6.0
    cycler==0.10.0
    future==0.18.2
    isort==4.3.21
    kiwisolver==1.1.0
    lazy-object-proxy==1.4.3
    matplotlib==3.1.1
    mccabe==0.6.1
    numpy==1.17.3
    pefile==2019.4.18
    plint==0.1
    pycparser==2.19
    pylint==2.4.3
    pyparsing==2.4.2
    PyQt5==5.13.2
    PyQt5-sip==12.7.0
    python-dateutil==2.8.1
    pywin32-ctypes==0.2.0
    scipy==1.3.1
    six==1.12.0
    typed-ast==1.4.0
    wrapt==1.11.2

"""

Usetex Demo

Shows how to use latex in a plot.

Also, refer to the :doc:/tutorials/text/usetex guide.
This code from: https://matplotlib.org/3.1.1/gallery/text_labels_and_annotations/usetex_demo.html


import numpy as np
import matplotlib.pyplot as plt
plt.rc('text', usetex=True)

# interface tracking profiles
N = 500
delta = 0.6
X = np.linspace(-1, 1, N)
plt.plot(X, (1 - np.tanh(4 * X / delta)) / 2,    # phase field tanh profiles
         X, (1.4 + np.tanh(4 * X / delta)) / 4, "C2",  # composition profile
         X, X < 0, 'k--')                        # sharp interface

# legend
plt.legend(('phase field', 'level set', 'sharp interface'),
           shadow=True, loc=(0.01, 0.48), handlelength=1.5, fontsize=16)

# the arrow
plt.annotate("", xy=(-delta / 2., 0.1), xytext=(delta / 2., 0.1),
             arrowprops=dict(arrowstyle="<->", connectionstyle="arc3"))
plt.text(0, 0.1, r'$\delta$',
         {'color': 'black', 'fontsize': 24, 'ha': 'center', 'va': 'center',
          'bbox': dict(boxstyle="round", fc="white", ec="black", pad=0.2)})

# Use tex in labels
plt.xticks((-1, 0, 1), ('$-1$', r'$\pm 0$', '$+1$'), color='k', size=20)

# Left Y-axis labels, combine math mode and text mode
plt.ylabel(r'\bf{phase field} $\phi$', {'color': 'C0', 'fontsize': 20})
plt.yticks((0, 0.5, 1), (r'\bf{0}', r'\bf{.5}', r'\bf{1}'), color='k', size=20)

# Right Y-axis labels
plt.text(1.02, 0.5, r"\bf{level set} $\phi$", {'color': 'C2', 'fontsize': 20},
         horizontalalignment='left',
         verticalalignment='center',
         rotation=90,
         clip_on=False,
         transform=plt.gca().transAxes)

# Use multiline environment inside a `text`.
# level set equations
eq1 = r"\begin{eqnarray*}" + \
      r"|\nabla\phi| &=& 1,\\" + \
      r"\frac{\partial \phi}{\partial t} + U|\nabla \phi| &=& 0 " + \
      r"\end{eqnarray*}"
plt.text(1, 0.9, eq1, {'color': 'C2', 'fontsize': 18}, va="top", ha="right")

# phase field equations
eq2 = r'\begin{eqnarray*}' + \
      r'\mathcal{F} &=& \int f\left( \phi, c \right) dV, \\ ' + \
      r'\frac{ \partial \phi } { \partial t } &=& -M_{ \phi } ' + \
      r'\frac{ \delta \mathcal{F} } { \delta \phi }' + \
      r'\end{eqnarray*}'
plt.text(0.18, 0.18, eq2, {'color': 'C0', 'fontsize': 16})

plt.text(-1, .30, r'gamma: $\gamma$', {'color': 'r', 'fontsize': 20})
plt.text(-1, .18, r'Omega: $\Omega$', {'color': 'b', 'fontsize': 20})

plt.show()
@ImportanceOfBeingErnest
Copy link
Member

Since the figure in the documentation is produced via the exact code that gets shown, we are sure that the code itself is fine.
You did not specify the matplotlib version in use in the issue report though.

More generally, I suspect you may have a problem with your latex installation. Are you sure latex is installed correctly, and that latex.exe is in your system PATH?

@ImportanceOfBeingErnest ImportanceOfBeingErnest added the Community support Users in need of help. label Dec 1, 2019
@Echeban
Copy link
Author

Echeban commented Dec 2, 2019

Sorry, using Matplotlib=3.1.1. I edited my post to include the pip freeze list so everything I have installed is listed.
Yes, latex.exe in on the path: C:\Program Files\MiKTeX 2.9\miktex\bin\x64
I opened a windows cmd shell to run it > latex helloworld!
where helloworld!.tex is a small document. It produced helloworld!.dvi which is correct.
On the same cmd shell I did > activate.bat to enter the venv, then
venv > python usetex_demo.py
I get Figure 1, empty and (apparently) frozen.
This time I let it there, (apparently) frozen and went for coffee. When I came back, it was rendered. My problem is that it takes a long time to render. Maybe it was downloading some latex package!
Thanks for the advice!

@ImportanceOfBeingErnest
Copy link
Member

In case it was downloading some package in the background, it should now be much faster when run a second time. Is that what you observe?

@Echeban
Copy link
Author

Echeban commented Dec 2, 2019 via email

@Echeban
Copy link
Author

Echeban commented Dec 2, 2019 via email

@tacaswell
Copy link
Member

We have had reports of very slow render times when calling out latex in both windows and osx.

How long does it take you to compile a trivial (~1 equation + required boiler plate) tex document on your system?

@Echeban
Copy link
Author

Echeban commented Dec 2, 2019 via email

@ImportanceOfBeingErnest
Copy link
Member

Running the example takes ~6 seconds for me on Windows with MikTeX. I didn't specifically test, but I would think running latex 13 times takes at least the same amount of time, so I didn't ever consider this unusual. Still, if this is considered unexpected, we can also reopen this?

@ImportanceOfBeingErnest ImportanceOfBeingErnest changed the title https://matplotlib.org/3.1.1/gallery/text_labels_and_annotations/usetex_demo.html Usetex demo is slow on windows Dec 2, 2019
@anntzer anntzer added Performance topic: text/usetex and removed Community support Users in need of help. labels Dec 2, 2019
@anntzer anntzer reopened this Dec 2, 2019
@anntzer
Copy link
Contributor

anntzer commented Dec 2, 2019

It is "well-known" that subprocesses are slow on Windows.
I think it should be possible to make texmanager just launch a single tex instance and interact with it over stdin to generate pages on the fly, which may help with performance. Would appreciate having my other texmanager refactoring (#14044... and some followups) go in first before trying to work on that, though ;-)
-- edit: not sure that tex can interactively output the dvi file, though...

Another idea may be to use the mylatexformat package to try saving a bit of time on the preamble loading?

@github-actions
Copy link

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!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Jun 30, 2023
@anntzer anntzer added keep Items to be ignored by the “Stale” Github Action and removed status: inactive Marked by the “Stale” Github Action labels Jun 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
keep Items to be ignored by the “Stale” Github Action Performance topic: text/usetex
Projects
None yet
Development

No branches or pull requests

4 participants