When saving a plot in pdf
format matplotlib doens't retain transparency. I have tried in svg
instead and here it does, so it is able to save the figure with transparency.
I have seen solutions such as in Matplotlib plots lose transparency when saving as .pdf but setting the axes to rasterized doesn't work for me. Is this a bug in matplotlib or am I doing something wrong?
Note: I am using python 3.9.2
CODE
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 2*np.pi)
y = np.cos(x)
fig, ax = plt.subplots(figsize=(10,6))
ax.plot(x, y, '--')
fig.savefig('example.pdf', transparent=True, bbox_inches='tight')
fig.savefig('example.svg', transparent=True, bbox_inches='tight')