To plot a watermark image in Matplotlib, we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- Return a sample data file using get_sample_data() method.
- Create a figure and a set of subplots.
- Plot the data points using plot() method, with alpha=0.7 and marker face color mfc="orange".
- Add a non-resampled image to the figure.
- To display the figure, use show() method.
Example
import numpy as np import matplotlib.cbook as cbook import matplotlib.image as image import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True with cbook.get_sample_data('logo2.png') as file: im = image.imread(file) fig, ax = plt.subplots() ax.plot(np.sin(10 * np.linspace(0, 1)), '-o', ms=20, alpha=0.7, mfc='orange') fig.figimage(im, 10, 10, zorder=3, alpha=.5) plt.show()