set_mpl_style#

This method prettifies matplotlib’s output by adjusting different parameters such as fonts, markersize, colormap, etc. This is useful, as it reduces the time to manually adjust those parameters on each image visualization in the notebook.

[1]:
import matplotlib.pyplot as plt
import numpy as np
import porespy as ps
import inspect
inspect.signature(ps.visualization.set_mpl_style)
[1]:
<Signature ()>

Let’s first visualize a figure without set_mpl_style:

[2]:
np.random.seed(10)
im1 = ps.generators.blobs(shape=[500, 500])
im2 = ps.filters.porosimetry(im1)
fig, ax = plt.subplots(1, 2)
ax[0].imshow(im1)
ax[1].imshow(im2)
[2]:
<matplotlib.image.AxesImage at 0x7fe14f6a7e80>
../../../_images/examples_visualization_reference_set_mpl_style_4_2.png

Now let’s apply set_mple_style and visualize multiple images. Note that to apply this style on all images in the code, you can write ps.visualization.set_mpl_style() once at the beginning of the code.

[3]:
ps.visualization.set_mpl_style()
fig, ax = plt.subplots(1, 2)
ax[0].imshow(im1)
ax[1].imshow(im2)
[3]:
<matplotlib.image.AxesImage at 0x7fe14f526a60>
../../../_images/examples_visualization_reference_set_mpl_style_6_1.svg