.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "intro/matplotlib/auto_examples/pretty_plots/plot_text_ext.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_intro_matplotlib_auto_examples_pretty_plots_plot_text_ext.py: Text printing decorated ======================= An example showing text printing and decorating the resulting figure. .. GENERATED FROM PYTHON SOURCE LINES 7-87 .. image-sg:: /intro/matplotlib/auto_examples/pretty_plots/images/sphx_glr_plot_text_ext_001.png :alt: plot text ext :srcset: /intro/matplotlib/auto_examples/pretty_plots/images/sphx_glr_plot_text_ext_001.png :class: sphx-glr-single-img .. code-block:: Python import numpy as np import matplotlib.pyplot as plt fig = plt.figure() plt.xticks([]) plt.yticks([]) eqs = [] eqs.append( r"$W^{3\beta}_{\delta_1 \rho_1 \sigma_2} = U^{3\beta}_{\delta_1 \rho_1} + \frac{1}{8 \pi 2} \int^{\alpha_2}_{\alpha_2} d \alpha^\prime_2 \left[\frac{ U^{2\beta}_{\delta_1 \rho_1} - \alpha^\prime_2U^{1\beta}_{\rho_1 \sigma_2} }{U^{0\beta}_{\rho_1 \sigma_2}}\right]$" ) eqs.append( r"$\frac{d\rho}{d t} + \rho \vec{v}\cdot\nabla\vec{v} = -\nabla p + \mu\nabla^2 \vec{v} + \rho \vec{g}$" ) eqs.append(r"$\int_{-\infty}^\infty e^{-x^2}dx=\sqrt{\pi}$") eqs.append(r"$E = mc^2 = \sqrt{{m_0}^2c^4 + p^2c^2}$") eqs.append(r"$F_G = G\frac{m_1m_2}{r^2}$") rng = np.random.default_rng() for i in range(24): index = rng.integers(0, len(eqs)) eq = eqs[index] size = rng.uniform(12, 32) x, y = rng.uniform(0, 1, 2) alpha = rng.uniform(0.25, 0.75) plt.text( x, y, eq, ha="center", va="center", color="#11557c", alpha=alpha, transform=plt.gca().transAxes, fontsize=size, clip_on=True, ) # Add a title and a box around it from matplotlib.patches import FancyBboxPatch ax = plt.gca() ax.add_patch( FancyBboxPatch( (-0.05, 0.87), width=0.66, height=0.165, clip_on=False, boxstyle="square,pad=0", zorder=3, facecolor="white", alpha=1.0, transform=plt.gca().transAxes, ) ) plt.text( -0.05, 1.02, " Text: plt.text(...)\n", horizontalalignment="left", verticalalignment="top", size="xx-large", transform=plt.gca().transAxes, ) plt.text( -0.05, 1.01, "\n\n Draw any kind of text ", horizontalalignment="left", verticalalignment="top", size="large", transform=plt.gca().transAxes, ) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.673 seconds) .. _sphx_glr_download_intro_matplotlib_auto_examples_pretty_plots_plot_text_ext.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_text_ext.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_text_ext.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_text_ext.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_