matplotlib在Seaborn下设置了小刻度

时间:2018-09-10 14:36:27

标签: python-3.x matplotlib seaborn

我有以下代码来绘制一系列子图:

minorLocator = AutoMinorLocator()
fig, ax = plt.subplots(4, 2, figsize=(8, 12))

data = np.random.rand(20,5)
ax[1, 1].plot(data, alpha=0.5)
ax[1, 1].set_title('Simulation')    
ax[1, 1].xaxis.set_minor_locator(minorLocator)

但是,该图未在情节中包括次要的“标记”。我也尝试过

ax[1, 1].plot(data, alpha=0.5)
ax[1, 1].xaxis.set_minor_locator(minorLocator)
ax[1, 1].xaxis.set_minor_formatter(NullFormatter())

但它也失败。由于我正在使用seaborn样式,因此我怀疑有必要重写Seaborn参数,但是我不确定如何使用。这是我的Seaborn实现方式

import seatborn as sns
sns.set()

如何在“ x”轴上添加“每日”标记?这些是我的情节的例子:

enter image description here

1 个答案:

答案 0 :(得分:2)

Seaborn Segmentation fault (core dumped)默认关闭刻度线。它使用.set()样式,该样式修改了matplotlib rc parameters并将darkgridxtick.bottom参数设置为ytick.leftsource)。

一种解决方案是将它们全局设置为False

True

sns.set(rc={"xtick.bottom" : True, "ytick.left" : True})

或者,也可以将它们打开以用于相关轴

sns.set()
plt.rcParams.update({"xtick.bottom" : True, "ytick.left" : True})