.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/plot_image.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_plot_image.py: Basic: PlotImage ================ You can use M.PlotImage to plot images on all of the Meshes. .. GENERATED FROM PYTHON SOURCE LINES 7-61 .. image-sg:: /examples/images/sphx_glr_plot_image_001.png :alt: TensorMesh, TreeMesh :srcset: /examples/images/sphx_glr_plot_image_001.png :class: sphx-glr-single-img .. code-block:: Python import discretize import matplotlib.pyplot as plt def run(plotIt=True): M = discretize.TensorMesh([32, 32]) v = discretize.utils.random_model(M.vnC, random_seed=789) v = discretize.utils.mkvc(v) O = discretize.TreeMesh([32, 32]) def function(cell): if ( cell.center[0] < 0.75 and cell.center[0] > 0.25 and cell.center[1] < 0.75 and cell.center[1] > 0.25 ): return 5 if ( cell.center[0] < 0.9 and cell.center[0] > 0.1 and cell.center[1] < 0.9 and cell.center[1] > 0.1 ): return 4 return 3 O.refine(function) P = M.get_interpolation_matrix(O.gridCC, "CC") ov = P * v if not plotIt: return fig, axes = plt.subplots(1, 2, figsize=(10, 5)) out = M.plot_image(v, grid=True, ax=axes[0]) cb = plt.colorbar(out[0], ax=axes[0]) cb.set_label("Random Field") axes[0].set_title("TensorMesh") out = O.plot_image(ov, grid=True, ax=axes[1], clim=[0, 1]) cb = plt.colorbar(out[0], ax=axes[1]) cb.set_label("Random Field") axes[1].set_title("TreeMesh") if __name__ == "__main__": run() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.270 seconds) .. _sphx_glr_download_examples_plot_image.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_image.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_image.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_image.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_