【问题标题】:Latex multiline bracket in a Matlab annotationMatlab注释中的乳胶多行括号
【发布时间】:2017-09-14 11:43:06
【问题描述】:

我希望用一些可以环绕 3 行的括号来注释用 Matlab 制作的图形。链接图中给出了一个例子:

我已成功添加第二个图例。但我想知道我怎样才能真正干净地做到这一点。我尝试做这样的事情

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')

但这给出了这样的结果:

最大的问题是

  • 我必须调整注释的位置...但这没什么大不了的。我可以花一些时间把它定位好。
  • 支架太大...我对此没有解决办法。我怎么能这样做?

问题是:

  1. 支架可以缩小吗?
  2. 如果不能,是否可以通过其他方式完成?

【问题讨论】:

    标签: matlab latex matlab-figure legend legend-properties


    【解决方案1】:

    我个人认为支架看起来不错,担心确切的尺寸有点分散注意力。

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

    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));
    

    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 网站无耻地窃取了这些代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-19
      • 2012-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多