Masks for Cloud plots
Import modules and setup font.
In [1]:
Copied!
import os
from ScanPyImports.plotter import DataPlotter, mask_from_path, get_fontname_list
import os
from ScanPyImports.plotter import DataPlotter, mask_from_path, get_fontname_list
In [2]:
Copied!
# Initailize DataPlotter with directory
plotter = DataPlotter('../../ScanPyImports')
# In this example, we use the Impact font
plotter.settings.set_font('Impact')
# If you are not on Windows, you might not have it.
# Either skip the previous step or choose another font
if 'Impact' in get_fontname_list():
print('"Impact" is installed on your computer')
else:
print('"Impact" is not installed!')
print('Use `get_fontname_list()` to check which fonts are installed on your computer.')
# Initailize DataPlotter with directory
plotter = DataPlotter('../../ScanPyImports')
# In this example, we use the Impact font
plotter.settings.set_font('Impact')
# If you are not on Windows, you might not have it.
# Either skip the previous step or choose another font
if 'Impact' in get_fontname_list():
print('"Impact" is installed on your computer')
else:
print('"Impact" is not installed!')
print('Use `get_fontname_list()` to check which fonts are installed on your computer.')
"Impact" is installed on your computer
You can use any png
image as a mask for the WordCloud plot.
Here is an example with an image included in the package. You can use your own image!
In [3]:
Copied!
# File with the image to use as a mask
path = r'../../ScanPyImports/images'
file_img = 'star.png'
# Get the mask of the image (np.array)
mask = mask_from_path(os.path.join(path, file_img))
# Plot
fig, ax, *_ = plotter.cloud_frequencies(mask=mask)
# File with the image to use as a mask
path = r'../../ScanPyImports/images'
file_img = 'star.png'
# Get the mask of the image (np.array)
mask = mask_from_path(os.path.join(path, file_img))
# Plot
fig, ax, *_ = plotter.cloud_frequencies(mask=mask)
In the image folder of the package, you can find other images to use as masks.
Here is a showcase of the available images.
In [4]:
Copied!
import matplotlib.pyplot as plt
# Helper function to get the mask from the file image
mask = lambda file_img: mask_from_path(os.path.join(path, file_img))
# Set the size for the plots
size = 3
# Create a mosaic of subplots for each shape/mask
fig, axs = plt.subplot_mosaic(
[['default', 'star'], ['circle', 'triangle']],
figsize=(size * 2, size * 2),
layout='constrained'
)
# Default shape plot
fig, axs['default'], *_ = plotter.cloud_frequencies(ax=axs['default'])
# Plot for other shapes
for shape in ['star', 'circle', 'triangle']:
fig, axs[shape], *_=plotter.cloud_frequencies(ax=axs[shape]
, mask=mask(f'{shape}.png')
)
import matplotlib.pyplot as plt
# Helper function to get the mask from the file image
mask = lambda file_img: mask_from_path(os.path.join(path, file_img))
# Set the size for the plots
size = 3
# Create a mosaic of subplots for each shape/mask
fig, axs = plt.subplot_mosaic(
[['default', 'star'], ['circle', 'triangle']],
figsize=(size * 2, size * 2),
layout='constrained'
)
# Default shape plot
fig, axs['default'], *_ = plotter.cloud_frequencies(ax=axs['default'])
# Plot for other shapes
for shape in ['star', 'circle', 'triangle']:
fig, axs[shape], *_=plotter.cloud_frequencies(ax=axs[shape]
, mask=mask(f'{shape}.png')
)