Get tiled chart layout for chart container subclass


tcl = getLayout(obj)


tcl = getLayout(obj) returns the tiled chart layout for a chart object that inherits from the base class.

Input Arguments

expand all

Object of the class that inherits from the base class.

Output Arguments

expand all

TiledChartLayout object. Use tcl when you are developing a chart that contains a polar plot, a geographic plot, or a tiling of multiple plots. You can configure certain aspects of the layout, such as the number of tiles, the location of each axes object, and the spacing between the tiles.



To learn about attributes of methods, see Method Attributes.


expand all

Define a class called CartPolarPlot that plots data in Cartesian and polar coordinates.

To define the class, create a file called CartPolarPlot.m that contains the following class definition with these features:

  • Three public properties: XData and YData to store the coordinate data, and LineColor to control the color of the lines

  • Four private properties that store the two lines and axes objects

  • A setup method that configures the layout, creates the axes, and initializes the two Line objects

  • An update method that updates the Line objects when the user changes the value of one or more public properties

classdef CartPolarPlot <
        XData (1,:) double = NaN
        YData (1,:) double = NaN
        LineColor (1,3) double {mustBeGreaterThanOrEqual(LineColor,0),...
            mustBeLessThanOrEqual(LineColor,1)} = [.5 0 1]
    properties(Access = private,Transient,NonCopyable)
        CartesianLine (1,1)
        PolarLine (1,1)
        CartesianAx (1,1)
        PolarAx (1,1)
    methods(Access = protected)
        function setup(obj)
            % Get the layout and create the axes
            tcl = getLayout(obj);
            tcl.GridSize = [1 2];
            obj.CartesianAx = axes(tcl);
            obj.PolarAx = polaraxes(tcl);
            % Move the polar axes to the second tile
            obj.PolarAx.Layout.Tile = 2;
            % Create the Cartesian and polar lines
            obj.CartesianLine = plot(obj.CartesianAx,NaN,NaN);
            obj.PolarLine = polarplot(obj.PolarAx,NaN,NaN);
        function update(obj)
            % Update Cartesian line
            obj.CartesianLine.XData = obj.XData;
            obj.CartesianLine.YData = obj.YData;
            obj.CartesianLine.Color = obj.LineColor;
            % Update polar line
            obj.PolarLine.Color = obj.LineColor;
            obj.PolarLine.ThetaData = obj.XData;
            obj.PolarLine.RData = obj.YData;

Next, create a set of x- and y-coordinates. Then plot the coordinates by calling the CartPolarPlot constructor method with the 'XData' and 'YData' name-value pair arguments.

x = 0:0.01:2*pi;
y = sin(2*x).*cos(2*x);

Introduced in R2020a