如何在图例项目中换行
How to break lines in the figure legend items
假设我想在单个图中绘制数据及其拟合曲线。在图例项中,第一项应为 'data',第二项的第一行应为 'fitted line',第二项的第二行应包含拟合参数 'a' 和 'b' 或斜率和截距。
我尝试了以下方法,但它不起作用
[f,gof] = fit(x,y,linearfittype);
legend(data,{'fitted curve',['a=' num2str(f.a)],['b=' num2str(f.b)],['R-squared=' num2str(gof.rsquare)]});
我尝试了下一页中的建议,但 none 行得通
http://www.mathworks.com/matlabcentral/newsreader/view_thread/96715
我还想在两个图例项之间使用换行符或垂直线 space
使用 sprintf
应该根据需要创建换行符(使用 \n
)。例如试试这个:
T = sprintf( 'a = %0.2f\nb = %0.2f\nR-squared = %0.2f',f.a,f.b,gof.rsquare);
legend(data,{'fitted curve',T});
假设我想在单个图中绘制数据及其拟合曲线。在图例项中,第一项应为 'data',第二项的第一行应为 'fitted line',第二项的第二行应包含拟合参数 'a' 和 'b' 或斜率和截距。
我尝试了以下方法,但它不起作用
[f,gof] = fit(x,y,linearfittype);
legend(data,{'fitted curve',['a=' num2str(f.a)],['b=' num2str(f.b)],['R-squared=' num2str(gof.rsquare)]});
我尝试了下一页中的建议,但 none 行得通 http://www.mathworks.com/matlabcentral/newsreader/view_thread/96715
我还想在两个图例项之间使用换行符或垂直线 space
使用 sprintf
应该根据需要创建换行符(使用 \n
)。例如试试这个:
T = sprintf( 'a = %0.2f\nb = %0.2f\nR-squared = %0.2f',f.a,f.b,gof.rsquare);
legend(data,{'fitted curve',T});