我正在绘制收敛图,并使用连接的箱线图来显示偏差:
由于某种原因,Matplotlib强制每个箱线图都有刻度线,我似乎无法将它们删除。 我当前绘图的代码大致如下:
我尝试了多种在MPL中可用的轴刻度方式。
1)试图让MPL自动完成工作:
![Connected boxplots](https://istack.dev59.com/7I3xM.webp)
label = ["" for i in range(160)]
no_labels = int(np.floor(len(label)/20))
for i in range(no_labels):
label[i*20] = str(i*no_samples/no_labels)
# Weird behaviour for the last label so adding it manually
label[-1] = no_samples
fig = plt.figure(figsize=(10,5))
ax = fig.add_axes([0,0,1,1])
ax.set_xlabel("Samples", labelpad=10)
ax.set_ylabel("Error (MSE)", labelpad=10)
ax.set_ylim(0, 0.11)
ax.boxplot(data, flierprops=flyprops, showcaps=False,
boxprops=colorprops, whiskerprops={'color' : 'tab:blue'},
labels=label, patch_artist=True)
我尝试了多种在MPL中可用的轴刻度方式。
1)试图让MPL自动完成工作:
ax.xaxis.set_major_locator(MultipleLocator(20))
2)手动设置刻度:ax.set_xticks([list_of_ticks])
3)尝试一种变通方法 ax.xaxis.set_minor_locator(MultipleLocator(20))
# Removing major ticks, setting minor ticks
ax.xaxis.set_tick_params(which='major', size=0, width=2, direction='in')
ax.yaxis.set_tick_params(which='major', size=5, width=2, direction='in')
我尝试了这些方法但都没有奏效,不确定原因。我认为可能与我的label
变量有关,但如果不以这种方式包括它,则MPL会对每个条目都包含轴标签,这样会很混乱。
如何在连通的箱线图中每1000个条目设置一次轴刻度?
编辑:输入数据是形状为(15,160)的numpy数组,其中绘制了160个由15个样本组成的箱线图。例如,3个样本的5个箱线图的示例数据如下:
np.random.rand(3,5)
>>> array([[0.05942481, 0.03408175, 0.84021109, 0.27531937, 0.62428798],
[0.24658313, 0.77910387, 0.2161348 , 0.39101172, 0.14038211],
[0.40694432, 0.22979738, 0.87056873, 0.788295 , 0.29337562]])