I need to generate a figure in PDF format for better quality (eps would still be good). In the figure, I need an oscillatory background, which is the actual signal, with a thin linewidth and a thicker (3 times) moving average filter line in the middle.
If I save the image in .png the desired linewidths are kept, the same does not apply for .pdf, .eps and .pgf, for which there seems to be a minimum linewidth, even though I didn't find anything in this sense on the docs. I'm running on Spyder with Python 3.7.3, updated matplotlib. I tried both to specify the linewidth into the ax.plot() call and also from rcParams but the behavior does not change: only .png keeps the correct format.
I attach the function which does the actual plot:
import matplotlib.pyplot as plt
import numpy as np
def data_plot(xaxis, sequences, xlabel, ylabel, legend, widths,
alphas, colors, fil):
n = len(sequences)
fig, ax = plt.subplots(figsize=(10,6))
for i in range(n):
ax.plot(xaxis, sequences[i], linewidth=widths[i], alpha=alphas[i],
color=colors[i])
ax.plot(xaxis[int(fil/2)-1:len(xaxis)-int(fil/2)],
np.convolve(sequences[i],np.ones(fil)/fil,mode='valid'),
linewidth=4*widths[i], alpha=2*alphas[i], color=colors[i],
label=legend[i])
ax.set_xlabel(xlabel)
ax.set_ylabel(ylabel)
ax.legend(loc='upper right', prop={'size': 12})
plt.show()
seq = [np.random.uniform(12,14,500), np.random.uniform(11,12.5,500),
np.random.uniform(12.7,15,500)]
x = np.linspace(1,100,500)
data_plot(x,seq,'x','y',['A','B','C'],
[0.2,0.2,0.2],[0.5,0.4,0.3],['C0','C1','C2'],10)
plt.savefig('figure.png')
plt.savefig('figure.pdf')