From a0f91fa6ae94ed6955e79e0bdf8b98627db098ad Mon Sep 17 00:00:00 2001 From: helmiriawan Date: Sun, 5 Mar 2017 21:36:38 +0100 Subject: [PATCH 1/3] merged the tex_X.py files into a single file tex.py --- .../pylab_examples/{tex_demo.py => tex.py} | 24 +++++++++++++-- examples/pylab_examples/tex_unicode_demo.py | 30 ------------------- 2 files changed, 21 insertions(+), 33 deletions(-) rename examples/pylab_examples/{tex_demo.py => tex.py} (56%) delete mode 100644 examples/pylab_examples/tex_unicode_demo.py diff --git a/examples/pylab_examples/tex_demo.py b/examples/pylab_examples/tex.py similarity index 56% rename from examples/pylab_examples/tex_demo.py rename to examples/pylab_examples/tex.py index f5db743b7889..cc81ece5bf6a 100644 --- a/examples/pylab_examples/tex_demo.py +++ b/examples/pylab_examples/tex.py @@ -13,11 +13,14 @@ ~/.tex.cache """ +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.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]) @@ -27,8 +30,23 @@ 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.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() + + + +plt.figure(2, 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 (\u00B0/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/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() From 78027499b14a0048f4e6af1302961a2933b98b73 Mon Sep 17 00:00:00 2001 From: Nelle Varoquaux Date: Sat, 11 Mar 2017 13:14:55 -0800 Subject: [PATCH 2/3] DOC minor fixes to plot_tex.py --- doc/devel/documenting_mpl.rst | 2 +- examples/pyplots/tex_demo.py | 39 ------------------- .../tex_demo.py} | 37 ++++++------------ pytest.ini | 1 - tutorials/01_introductory/sample_plots.py | 4 +- tutorials/text/usetex.py | 15 +++---- 6 files changed, 23 insertions(+), 75 deletions(-) delete mode 100644 examples/pyplots/tex_demo.py rename examples/{pylab_examples/tex.py => text_labels_and_annotations/tex_demo.py} (53%) 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/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/pylab_examples/tex.py b/examples/text_labels_and_annotations/tex_demo.py similarity index 53% rename from examples/pylab_examples/tex.py rename to examples/text_labels_and_annotations/tex_demo.py index cc81ece5bf6a..3850638bf0a2 100644 --- a/examples/pylab_examples/tex.py +++ b/examples/text_labels_and_annotations/tex_demo.py @@ -1,7 +1,7 @@ """ -======== -Tex Demo -======== +================================= +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 @@ -12,6 +12,8 @@ time, the run may be silent, as a lot of the information is cached in ~/.tex.cache +Notice how the the label for the y axis is provided using unicode! + """ from __future__ import unicode_literals import numpy as np @@ -21,32 +23,17 @@ import matplotlib.pyplot as plt -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() - - -plt.figure(2, 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 (\u00B0/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) +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 (\u00B0/sec)}') +ax.set_title(r'\TeX\ is Number $\displaystyle\sum_{n=1}^\infty' + r'\frac{-e^{i\pi}}{2^n}$!') 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: From 864138f1e38b98ffd9e58ce99aef7da5dd911a1a Mon Sep 17 00:00:00 2001 From: sindunuragarp Date: Sun, 12 Mar 2017 22:00:59 +0100 Subject: [PATCH 3/3] Removed unused code + made unicode example clearer + added back plot args --- examples/text_labels_and_annotations/tex_demo.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/examples/text_labels_and_annotations/tex_demo.py b/examples/text_labels_and_annotations/tex_demo.py index 3850638bf0a2..417bbc63d69b 100644 --- a/examples/text_labels_and_annotations/tex_demo.py +++ b/examples/text_labels_and_annotations/tex_demo.py @@ -9,8 +9,7 @@ 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 +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! @@ -26,14 +25,11 @@ t = np.linspace(0.0, 1.0, 100) s = np.cos(4 * np.pi * t) + 2 -t = np.arange(0.0, 1.0 + 0.01, 0.01) -s = np.cos(2*2*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 (\u00B0/sec)}') +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}$!') + r'\frac{-e^{i\pi}}{2^n}$!', fontsize=16, color='r') plt.show()