I can’t figure out how to make the graph transparent. I have a waveform graph from audio and fill the space with a background, I’m trying, but the background still appears on the graph.
def generate_waveform_image(save_dir, audio_file, output_filename, color='white', alpha=0, figsize=(12, 2), dpi=75):
fig, ax = plt.subplots(figsize=figsize, dpi=dpi, frameon=False)
plt.subplots_adjust(left=0, right=1, bottom=0, top=1)
samples, sr = librosa.load(audio_file, sr=None, mono=True)
times = np.arange(len(samples)) / sr
ax.plot(times, samples, color=color, alpha=alpha, linewidth=0.1)
ax.margins(0, 0)
ax.axis('off')
plt.savefig(os.path.join(save_dir, f'{output_filename}.png'), transparent=True, bbox_inches='tight',
pad_inches=0)
I tried everything and still_between, the background fills the entire image, but I need it to be like this:

ax.fill_between(times, -1, 1, color='gray', alpha=1)
plt.savefig(..., transparent=True)makes the background transparent. But you seem to want to have the foreground transparent.Here is an approach:
'agg'backend, so nothing is shown on-screenfig.canvas.draw()is needed to fill in the pixelsThis is how the image looks inside Gimp: