diff --git a/doc/devel/documenting_mpl.rst b/doc/devel/documenting_mpl.rst index 226971ba11bc..cfb08a6d28ba 100644 --- a/doc/devel/documenting_mpl.rst +++ b/doc/devel/documenting_mpl.rst @@ -352,7 +352,7 @@ git. Please also add a line to the README in doc/pyplots for any additional requirements necessary to generate a new figure. Once these steps have been taken, these figures can be included in the usual way:: - .. plot:: mpl_examples/pyplots/tex_unicode_demo.py + .. plot:: mpl_examples/text_labels_and_annotations/tex_demo.py :include-source: Examples diff --git a/examples/pylab_examples/tex_demo.py b/examples/pylab_examples/tex_demo.py deleted file mode 100644 index f5db743b7889..000000000000 --- a/examples/pylab_examples/tex_demo.py +++ /dev/null @@ -1,34 +0,0 @@ -""" -======== -Tex Demo -======== - -You can use TeX to render all of your matplotlib text if the rc -parameter text.usetex is set. This works currently on the agg and ps -backends, and requires that you have tex and the other dependencies -described at http://matplotlib.org/users/usetex.html -properly installed on your system. The first time you run a script -you will see a lot of output from tex and associated tools. The next -time, the run may be silent, as a lot of the information is cached in -~/.tex.cache - -""" -import numpy as np -import matplotlib.pyplot as plt - - -plt.rc('text', usetex=True) -plt.rc('font', family='serif') -plt.figure(1, figsize=(6, 4)) -ax = plt.axes([0.1, 0.1, 0.8, 0.7]) -t = np.linspace(0.0, 1.0, 100) -s = np.cos(4 * np.pi * t) + 2 -plt.plot(t, s) - -plt.xlabel(r'\textbf{time (s)}') -plt.ylabel(r'\textit{voltage (mV)}', fontsize=16) -plt.title(r"\TeX\ is Number $\displaystyle\sum_{n=1}^\infty" - r"\frac{-e^{i\pi}}{2^n}$!", fontsize=16, color='r') -plt.grid(True) -plt.savefig('tex_demo') -plt.show() diff --git a/examples/pylab_examples/tex_unicode_demo.py b/examples/pylab_examples/tex_unicode_demo.py deleted file mode 100644 index c2d87520bee7..000000000000 --- a/examples/pylab_examples/tex_unicode_demo.py +++ /dev/null @@ -1,30 +0,0 @@ -""" -================ -Tex Unicode Demo -================ - -This demo is tex_demo.py modified to have unicode. See that file for -more information. - --*- coding: utf-8 -*- -""" - -from __future__ import unicode_literals -import numpy as np -import matplotlib -matplotlib.rcParams['text.usetex'] = True -matplotlib.rcParams['text.latex.unicode'] = True -import matplotlib.pyplot as plt - -plt.figure(1, figsize=(6, 4)) -ax = plt.axes([0.1, 0.1, 0.8, 0.7]) -t = np.arange(0.0, 1.0 + 0.01, 0.01) -s = np.cos(2*2*np.pi*t) + 2 -plt.plot(t, s) - -plt.xlabel(r'\textbf{time (s)}') -plt.ylabel('\\textit{Velocity (\N{DEGREE SIGN}/sec)}', fontsize=16) -plt.title(r'\TeX\ is Number $\displaystyle\sum_{n=1}^\infty' - r'\frac{-e^{i\pi}}{2^n}$!', fontsize=16, color='r') -plt.grid(True) -plt.show() diff --git a/examples/pyplots/tex_demo.py b/examples/pyplots/tex_demo.py deleted file mode 100644 index 9752bd0c2d6e..000000000000 --- a/examples/pyplots/tex_demo.py +++ /dev/null @@ -1,39 +0,0 @@ -""" -======== -Tex Demo -======== - -Demo of TeX rendering. - -You can use TeX to render all of your matplotlib text if the rc -parameter text.usetex is set. This works currently on the agg and ps -backends, and requires that you have tex and the other dependencies -described at http://matplotlib.org/users/usetex.html -properly installed on your system. The first time you run a script -you will see a lot of output from tex and associated tools. The next -time, the run may be silent, as a lot of the information is cached in -~/.tex.cache - -""" -import numpy as np -import matplotlib.pyplot as plt - - -# Example data -t = np.arange(0.0, 1.0 + 0.01, 0.01) -s = np.cos(4 * np.pi * t) + 2 - -plt.rc('text', usetex=True) -plt.rc('font', family='serif') -plt.plot(t, s) - -plt.xlabel(r'\textbf{time} (s)') -plt.ylabel(r'\textit{voltage} (mV)',fontsize=16) -plt.title(r"\TeX\ is Number " - r"$\displaystyle\sum_{n=1}^\infty\frac{-e^{i\pi}}{2^n}$!", - fontsize=16, color='gray') -# Make room for the ridiculously large title. -plt.subplots_adjust(top=0.8) - -plt.savefig('tex_demo') -plt.show() diff --git a/examples/text_labels_and_annotations/tex_demo.py b/examples/text_labels_and_annotations/tex_demo.py new file mode 100644 index 000000000000..417bbc63d69b --- /dev/null +++ b/examples/text_labels_and_annotations/tex_demo.py @@ -0,0 +1,35 @@ +""" +================================= +Rendering math equation using TeX +================================= + +You can use TeX to render all of your matplotlib text if the rc +parameter text.usetex is set. This works currently on the agg and ps +backends, and requires that you have tex and the other dependencies +described at http://matplotlib.org/users/usetex.html +properly installed on your system. The first time you run a script +you will see a lot of output from tex and associated tools. The next +time, the run may be silent, as a lot of the information is cached. + +Notice how the the label for the y axis is provided using unicode! + +""" +from __future__ import unicode_literals +import numpy as np +import matplotlib +matplotlib.rcParams['text.usetex'] = True +matplotlib.rcParams['text.latex.unicode'] = True +import matplotlib.pyplot as plt + + +t = np.linspace(0.0, 1.0, 100) +s = np.cos(4 * np.pi * t) + 2 + +fig, ax = plt.subplots(figsize=(6, 4), tight_layout=True) +ax.plot(t, s) + +ax.set_xlabel(r'\textbf{time (s)}') +ax.set_ylabel('\\textit{Velocity (\N{DEGREE SIGN}/sec)}', fontsize=16) +ax.set_title(r'\TeX\ is Number $\displaystyle\sum_{n=1}^\infty' + r'\frac{-e^{i\pi}}{2^n}$!', fontsize=16, color='r') +plt.show() diff --git a/pytest.ini b/pytest.ini index 06adfff8d8fe..3c1f219d03d3 100644 --- a/pytest.ini +++ b/pytest.ini @@ -129,7 +129,6 @@ pep8ignore = *examples/pyplots/pyplot_mathtext.py E231 *examples/pyplots/pyplot_simple.py E231 *examples/pyplots/pyplot_two_subplots.py E302 - *examples/pyplots/tex_demo.py E231 *examples/pyplots/text_commands.py E231 *examples/pyplots/text_layout.py E231 *examples/pyplots/whats_new_1_subplot3d.py W391 diff --git a/tutorials/01_introductory/sample_plots.py b/tutorials/01_introductory/sample_plots.py index 675b7a601dc9..fb609c88317d 100644 --- a/tutorials/01_introductory/sample_plots.py +++ b/tutorials/01_introductory/sample_plots.py @@ -340,8 +340,8 @@ powerful, sometimes you need TeX. Matplotlib supports external TeX rendering of strings with the *usetex* option. -.. figure:: ../../gallery/pyplots/images/sphx_glr_tex_demo_001.png - :target: ../../gallery/pyplots/tex_demo.html +.. figure:: ../../gallery/text_labels_and_annotations/images/sphx_glr_tex_demo_001.png + :target: ../../gallery/text_labels_and_annotations/tex_demo.html :align: center :scale: 50 diff --git a/tutorials/text/usetex.py b/tutorials/text/usetex.py index f0971580724a..10ce0ff5c907 100644 --- a/tutorials/text/usetex.py +++ b/tutorials/text/usetex.py @@ -53,12 +53,12 @@ Here is the standard example, `tex_demo.py`: -.. figure:: ../../gallery/pyplots/images/sphx_glr_tex_demo_001.png - :target: ../../gallery/pyplots/tex_demo.html +.. figure:: ../../gallery/text_labels_and_annotations/images/sphx_glr_tex_demo_001.png + :target: ../../gallery/text_labels_and_annotations/tex_demo.html :align: center :scale: 50 - Tex Demo + TeX Demo Note that display math mode (``$$ e=mc^2 $$``) is not supported, but adding the command ``\displaystyle``, as in `tex_demo.py`, will produce the same @@ -76,15 +76,16 @@ usetex with unicode =================== + It is also possible to use unicode strings with the LaTeX text manager, here is -an example taken from `tex_unicode_demo.py`: +an example taken from `tex_demo.py`. The axis labels include Unicode text: -.. figure:: ../../gallery/pylab_examples/images/sphx_glr_tex_unicode_demo_001.png - :target: ../../gallery/pylab_examples/tex_unicode_demo.html +.. figure:: ../../gallery/text_labels_and_annotations/images/sphx_glr_tex_demo_001.png + :target: ../../gallery/text_labels_and_annotations/tex_demo.html :align: center :scale: 50 - Tex Unicode Demo + TeX Unicode Demo .. _usetex-postscript: