

.. _sphx_glr_gallery_pylab_examples_spy_demos.py:


=========
Spy Demos
=========

Plot the sparsity pattern of arrays




.. image:: /gallery/pylab_examples/images/sphx_glr_spy_demos_001.png
    :align: center





.. code-block:: python


    import matplotlib.pyplot as plt
    import numpy as np

    fig, axs = plt.subplots(2, 2)
    ax1 = axs[0, 0]
    ax2 = axs[0, 1]
    ax3 = axs[1, 0]
    ax4 = axs[1, 1]

    x = np.random.randn(20, 20)
    x[5, :] = 0.
    x[:, 12] = 0.

    ax1.spy(x, markersize=5)
    ax2.spy(x, precision=0.1, markersize=5)

    ax3.spy(x)
    ax4.spy(x, precision=0.1)

    plt.show()

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



.. container:: sphx-glr-footer


  .. container:: sphx-glr-download

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



  .. container:: sphx-glr-download

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

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

    `Generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_
