Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Seaborn plot saved to eps does not show grid

I have played around a bit and can't get saving a plot rendered with seaborn correctly. When using plt.savefig I lose the grid. However, using plt.show and then saving the figure manually works. This happens with eps and png as well. I need to render large amount of plots so this is a problem.

import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

sns.set(style = 'darkgrid', font_scale=2)
t = np.arange(100)
y = np.random.rand(len(t))
plt.plot(t,y)
plt.title('Test title')
plt.xlabel('Test xlab')
plt.ylabel('Tex $y_i = w_i x_i$')
plt.tight_layout()
#plt.show()
plt.savefig('test_plot.eps', format='eps')

Automatic save Automatic save

Manual save Manual save

like image 622
johnblund Avatar asked Oct 31 '22 04:10

johnblund


1 Answers

The solution was I had "savefig.transparent : True" in my matplotlibrc that I for some reason needed before. Changing this to False solved the problem in my case.

like image 113
johnblund Avatar answered Nov 15 '22 06:11

johnblund