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.

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

Let’s first visualize a figure without set_mpl_style:

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)
<matplotlib.image.AxesImage at 0x7f4deacd83d0>
../../../_images/cd9f6a495ecd72b40f29ed4ab732dd5a1791e5c2bf3444d05b6c63074a339bf2.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.

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