.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples_gallery/fields/random_fields.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_examples_gallery_fields_random_fields.py: Random scalar fields ==================== This example showcases several random fields .. GENERATED FROM PYTHON SOURCE LINES 7-30 .. image-sg:: /examples_gallery/fields/images/sphx_glr_random_fields_001.png :alt: Uniform, uncorrelated, Gaussian, power-law correlated, Gaussian, cosine correlated, Combined harmonic functions :srcset: /examples_gallery/fields/images/sphx_glr_random_fields_001.png :class: sphx-glr-single-img .. code-block:: Python import matplotlib.pyplot as plt from pde import ScalarField, UnitGrid # initialize grid and plot figure grid = UnitGrid([256, 256], periodic=True) fig, axes = plt.subplots(nrows=2, ncols=2) f1 = ScalarField.random_uniform(grid, -2.5, 2.5) f1.plot(ax=axes[0, 0], title="Uniform, uncorrelated") f2 = ScalarField.random_normal(grid, correlation="power law", exponent=-6) f2.plot(ax=axes[0, 1], title="Gaussian, power-law correlated") f3 = ScalarField.random_normal(grid, correlation="cosine", length_scale=30) f3.plot(ax=axes[1, 0], title="Gaussian, cosine correlated") f4 = ScalarField.random_harmonic(grid, modes=4) f4.plot(ax=axes[1, 1], title="Combined harmonic functions") plt.subplots_adjust(hspace=0.8) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.166 seconds) .. _sphx_glr_download_examples_gallery_fields_random_fields.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: random_fields.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: random_fields.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: random_fields.zip `