Matlab注释中的Latex多线支架

问题描述 投票:0回答:1

我正在寻找一个用Matlab制作的图形,用一些支架包围3行。附图中给出了一个例子:

enter image description here

我成功地添加了第二个传奇。但我想知道我怎么能干得这么干净。我尝试做这样的事情

str = '$S_n =$ $\left\{ \begin{tabular}{c} 0.5 MeV \\ 50 keV \\ 5 MeV \end{tabular}\right.$';
annotation('textbox',[0.325,0.175,0.1,0.1],'String',str,'Interpreter','latex','FitBoxToText','on','Linestyle','none')

但这给出了像这样的结果:

enter image description here

最大的问题是

  • 我必须调整注释的位置......但这不是什么大问题。我可以花一些时间来定位它。
  • 支架太大了......我没有解决方案。我怎么能这样做?

问题是:

  1. 支架可以缩小吗?
  2. 如果没有,这可以用另一种方式完成吗?
matlab latex matlab-figure legend legend-properties
1个回答
1
投票

我个人认为支架看起来不错,担心确切尺寸会让人分心。

但是,另一个选项是为图例添加标题。这将允许您表示每个图例所指的单位/参数,而不会使图例的每一行混乱。遗憾的是,这不是本机MATLAB功能,但我们可以强制它。确切的实现因matlab版本而异。

PRE 2014年代码

function zz_LegendTitle(LegendHandle , TitleText, Fontsize)
% Workaround to Matlab 2014 thinking that legends don't need titles.
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if ~exist('Fontsize','var'); Fontsize = 10; end 
if ~exist('TitleText','var'); TitleText = 'example text'; end 


% Create an invisible axes at the same position as the legend
hLegendAxes = axes('Parent',LegendHandle.Parent, 'Units',LegendHandle.Units, 'Position',LegendHandle.Position, ...
                   'XTick',[] ,'YTick',[], 'Color','none', 'YColor','none', 'XColor','none', 'HandleVisibility','off', 'HitTest','off');

% Add the axes title (will appear directly above the legend box)
hTitle = title(hLegendAxes, TitleText,...
                'interpreter','latex',...
                'FontWeight','normal',...
                'FontSize',Fontsize);  % Default is bold-11, which is too large

% Link between some property values of the legend and the new axes
hLinks = linkprop([LegendHandle,hLegendAxes], {'Units', 'Position', 'Visible'});
% persist hLinks, otherwise they will stop working when they go out of scope
setappdata(hLegendAxes, 'listeners', hLinks);

% Add destruction event listener (no need to persist here - this is done by addlistener)
addlistener(LegendHandle, 'ObjectBeingDestroyed', @(h,e)delete(hLegendAxes));

Legend Title Example

发布2014年代码

    hLegend = legend(LegTxt,...
        'interpreter','latex','FontSize',LegFontSize,...
        'location','eastoutside');
    %resize to fix the legend-enforced size change
    set(ax(1),'Units',units,'position',IcePosVec);

%Attach a title to legend (here be dragons. Matlab 2015+ workaround)
     hlt = text('some text',...
    'Parent', hLegend.DecorationContainer, ...
    'String', 'Title', ...
    'HorizontalAlignment', 'center', ...
    'VerticalAlignment', 'bottom', ...
    'Position', [0.5, 1.05, 0], ...
    'Units', 'normalized');

PS。在信用到期的情况下,我在大约一年前通过从优秀的Undocumented Matlab网站上无耻地窃取了这些代码。

© www.soinside.com 2019 - 2024. All rights reserved.