Per the DisplayName documentation, a newline character \n needs to be injected into the text, and this can easily be done through sprintf. One small but important complication is that escaping the standard LaTeX active character \ is required, so sprintf doesn't think LaTeX commands are one of its special characters (some variable names were changed to ensure the code runs):xErr = randn(1,1000);[mu, sig] = normfit(xErr);h = histogram(xErr, 100, 'Normalization','pdf');set(h,... 'DisplayName',... sprintf([... 'Standard deviation $\\sigma_{x} = $ ', num2str(sig),... '\nMean $\\mu_x = $ ', num2str(mu)]));hl = legend('Location', 'NorthWest');set(hl,'Interpreter','latex');我会亲自使用xErr = randn(1,1000);[mu, sig] = normfit(xErr);histogram(xErr, 100, 'Normalization','pdf');legText = {... sprintf([... 'Standard deviation $\\sigma_{x} = %9.7f$ \n ',... 'Mean $\\mu_x = %9.7f$' ],... [sig,mu])... };legend(legText,'Location', 'NorthWest','Interpreter','latex');但这只是美学. 这篇关于直方图图例中的多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-09 19:08