
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "gallery/misc/rasterization_demo.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        Click :ref:`here <sphx_glr_download_gallery_misc_rasterization_demo.py>`
        to download the full example code

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_gallery_misc_rasterization_demo.py:


==================
Rasterization Demo
==================

.. GENERATED FROM PYTHON SOURCE LINES 7-57



.. image:: /gallery/misc/images/sphx_glr_rasterization_demo_001.png
    :alt: No Rasterization, Rasterization, No Rasterization, Rasterization z$<-10$
    :class: sphx-glr-single-img


.. rst-class:: sphx-glr-script-out

 Out:

 .. code-block:: none

    The PostScript backend does not support transparency; partially transparent artists will be rendered opaque.






|

.. code-block:: default

    import numpy as np
    import matplotlib.pyplot as plt

    d = np.arange(100).reshape(10, 10)
    x, y = np.meshgrid(np.arange(11), np.arange(11))

    theta = 0.25*np.pi
    xx = x*np.cos(theta) - y*np.sin(theta)
    yy = x*np.sin(theta) + y*np.cos(theta)

    fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2)
    ax1.set_aspect(1)
    ax1.pcolormesh(xx, yy, d)
    ax1.set_title("No Rasterization")

    ax2.set_aspect(1)
    ax2.set_title("Rasterization")

    m = ax2.pcolormesh(xx, yy, d)
    m.set_rasterized(True)

    ax3.set_aspect(1)
    ax3.pcolormesh(xx, yy, d)
    ax3.text(0.5, 0.5, "Text", alpha=0.2,
             va="center", ha="center", size=50, transform=ax3.transAxes)

    ax3.set_title("No Rasterization")


    ax4.set_aspect(1)
    m = ax4.pcolormesh(xx, yy, d)
    m.set_zorder(-20)

    ax4.text(0.5, 0.5, "Text", alpha=0.2,
             zorder=-15,
             va="center", ha="center", size=50, transform=ax4.transAxes)

    ax4.set_rasterization_zorder(-10)

    ax4.set_title("Rasterization z$<-10$")


    # ax2.title.set_rasterized(True) # should display a warning

    plt.savefig("test_rasterization.pdf", dpi=150)
    plt.savefig("test_rasterization.eps", dpi=150)

    if not plt.rcParams["text.usetex"]:
        plt.savefig("test_rasterization.svg", dpi=150)
        # svg backend currently ignores the dpi


.. rst-class:: sphx-glr-timing

   **Total running time of the script:** ( 0 minutes  1.684 seconds)


.. _sphx_glr_download_gallery_misc_rasterization_demo.py:


.. only :: html

 .. container:: sphx-glr-footer
    :class: sphx-glr-footer-example



  .. container:: sphx-glr-download sphx-glr-download-python

     :download:`Download Python source code: rasterization_demo.py <rasterization_demo.py>`



  .. container:: sphx-glr-download sphx-glr-download-jupyter

     :download:`Download Jupyter notebook: rasterization_demo.ipynb <rasterization_demo.ipynb>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    Keywords: matplotlib code example, codex, python plot, pyplot
    `Gallery generated by Sphinx-Gallery
    <https://sphinx-gallery.readthedocs.io>`_
