Я строю несколько диаграмм и хотел бы удалить линии сетки, пересекающие данные, но сохранить линии главных осей.
Раньше я выполнял это с помощью sns.despine (), но я недавно обновил matplotlib, и он появляется где-то вдоль линии, это больше не работает.В большинстве решений, которые я видел, удаляются ОБА главные оси и линии сетки.
Например, один вопрос рекомендуется:
ax.grid(False)
, который удаляет линии сетки и линии главных осей.
A второе решение предложил явно задавать цвета позвоночника:
for spine in ['left','right','top','bottom']:
ax1.spines[spine].set_color('k')
Это не работает для меня.
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
%matplotlib inline
df = pd.read_csv('fig3full_tidy.csv', comment = '#')
df.head()
plt.style.use('dark_background')
fig, ax = plt.subplots()
# ax.grid(False)
barwidth = 0.2
temps = [15, 20, 25]
types = ['sc', 'sk', 'direct']
i = 1
for g in types:
for t in temps:
ys = df.loc[(df['Temperature'] == t) & (df['Genotype'] == g)].Fluorescence
xs = np.random.normal(i, 0.05, len(ys))
if g == 'sc':
c = '#f08073'
elif g == 'sk':
c= '#2b8cbe'
elif g == 'direct':
c = '#23ba23'
plt.plot(xs, ys, 'o', color= c, alpha= .7, zorder = 1)
plt.hlines(ys.mean(), color = 'white', xmin = i- barwidth, xmax = i+ barwidth, lw = 1, zorder = 2)
plt.errorbar(i, ys.mean(), yerr = ys.sem(), fmt = '-', ecolor = 'white', capsize = 0, elinewidth = 1, barsabove = True, zorder = 2)
i += 1
# plt.axvline(3.5, color = 'white', lw = 1)
labels= ['', '15', '20', '25', '15', '20', '25', '15', '20', '25']
plt.xlabel('Temperature ($^\circ$C)', fontsize = 14, fontname = 'Arial')
plt.xticks([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], labels, fontsize = 14)
sns.despine()
plt.ylabel('Fluorescence', fontsize = 14, fontname = 'Arial')
plt.yticks([0, 10000, 20000, 30000, 40000])
# plt.savefig('fig3.2_dark.pdf', bbox_inches='tight')
plt.show()
plt.close()
Желаемые результаты [Линии оситолько]: 
С sns.despine не работает, у меня много линий сетки [Слишком много]:

Если я установлю ax.grid (False), я получу слишком мало [Нет строк]:
