如何在箱线图的图例中强制换行?

How to force a line break in a legend of a boxplot?

我需要帮助来跳过箱线图图例中的线条:我有一个包含两个箱线图的图,每个箱线图都有一个很长的图例以适合一条线。

我试过了,X 是我的数据矩阵(两列):

boxplot(X,'Labels',{'1stpartofthelegend\newline2ndpartofthelegend','1stpartofthelegend\newline2ndpartofthelegend})

此解决方案适用于其他类型的绘图,例如 plotspread plot,所以我不明白为什么它在这里不起作用? 我找到了 this question,但这些解决方案对我不起作用,可能是因为我有更新的版本 (R2018b)。

我实际上想在 plotpsread 图上添加我的箱线图,但是当我这样做时,箱线图的图例胜过 plotspread 的图例(即使我添加没有图例的箱线图,plotspread 的先前图例是替换为“1”和“2”)。因此,防止箱线图删除以前的图例将是一个很好的解决方案,但由于我没有这样做,所以我试图找到另一种方法。

感谢您的帮助

您想为多条线设置箱线图的 'Labels'。所以使用一个单元格:

Lbl = { {'1st entry (1st line)','2nd entry (1st line)'},...
        {'1st entry (2nd line)','2nd entry (2nd line)'} };
boxplot(rand(100,2),'Labels',Lbl)

编辑 LaTeX 命令在标题和标签中有效,但显然没有 interpreterTickLabelInterpreter 属性 for boxplot-Labels:

Error using internal.stats.parseArgs (line 42)

Invalid parameter name: TickLabelInterpreter.