I have had this issue for a few years now but never tried to resolve it. I'm using python for data processing and occasionally I want to use a Savitzy-Golay filter to smooth out my data. At the same time I want to plot those results and I like using the Latex computer modern font for figure labels, etc. The problem occurs when I simultaneously use the Savitzy-Golay filter:
from scipy.signal import savgol_filter
y_filt = savgol_filter(y,51,2)
and the Latex font:
rc('font',**{'family':'serif','serif':['Helvetica']})
rc('text',usetex=True)
The script "freezes" and no plot is produced. If I comment out rc('text',usetex=True), the script runs normally and the figure is produced; however, not with the font style I want. Also, if I comment out y_filt = savgol_filter(y,51,2) and leave rc('text',usetex=True) uncommented (and use a different data smoothing algorithm), the figure is produced. Finally, the script runs fine if I don't use any plot commands. Below are the plot commands I typically use:
from matplotlib import pyplot as plt
from matplotlib import rc
import matplotlib.gridspec as gridspec
rc('font',**{'family':'serif','serif':['Helvetica']})
rc('text',usetex=True)
figx = 2
figy = 4
fig = plt.figure()
ax1 = plt.subplot2grid((1,1),(0,0))
ax1.plot(x,y_filt,color='k',lw=1)
fig.set_size_inches(figx,figy)
fig.savefig(dirFigs+'A1_extracted.pdf',dpi=600,bbox_inches='tight')
I'm at a loss as to why the script freezes when savgol_filter and rc are used. I'm running Python 3.8.3 through Anaconda on macOS 11.6.1.
Thank you in advance.