Main Content

getLegend

类: matlab.graphics.chartcontainer.mixin.Legend
命名空间: matlab.graphics.chartcontainer.mixin

获取图例 mixin 子类的图例对象

自 R2019b 起

语法

lgd = getLegend(obj)

说明

lgd = getLegend(obj) 返回从 matlab.graphics.chartcontainer.mixin.Legend 类继承的图对象的图例。

输入参数

全部展开

matlab.graphics.chartcontainer.mixin.Legend 类继承的类的对象。

输出参数

全部展开

图的 Legend 对象。

属性

Protectedtrue

要了解方法的属性,请参阅方法属性

示例

全部展开

在类定义文件中创建 setup 方法。在该方法内,调用 getLegend 以获取图例对象 lgd。然后更改文本颜色、框边缘颜色和框线宽度。

classdef ConfigLegendChart < matlab.graphics.chartcontainer.ChartContainer & ...
        matlab.graphics.chartcontainer.mixin.Legend
    
    properties
        % ...
    end
    
    methods(Access = protected)
        function setup(obj)
            % Make legend visible
            obj.LegendVisible = 'on';
            
            % Get legend and set text color, edge color, and line width
            lgd = getLegend(obj);
            lgd.TextColor = [.3 .3 .3];
            lgd.EdgeColor = [.8 .8 .8];
            lgd.LineWidth = .7;
        end
        function update(obj)
            % ...
        end
    end
end

版本历史记录

在 R2019b 中推出