matlab.graphics.chartcontainer.ChartContainer.getLayout - Get tiled chart layout for chart container subclass - MATLAB (original) (raw)
Class: matlab.graphics.chartcontainer.ChartContainer
Namespace: matlab.graphics.chartcontainer
Get tiled chart layout for chart container subclass
Syntax
tcl = getLayout(obj)
Description
[tcl](#mw%5F59161bb2-35ee-41eb-8e76-e2663f648a1b) = getLayout([obj](#mw%5Fe3ac8a91-33e2-47ed-83ee-2bddf4382620))
returns the tiled chart layout for a chart object that inherits from thematlab.graphics.chartcontainer.ChartContainer
base class.
Input Arguments
Object of the class that inherits from thematlab.graphics.chartcontainer.ChartContainer
base class.
Output Arguments
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.
Examples
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
andYData
to store the coordinate data, andLineColor
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 twoLine
objects - An
update
method that updates theLine
objects when the user changes the value of one or more public properties
classdef CartPolarPlot < matlab.graphics.chartcontainer.ChartContainer properties XData (1,:) double = NaN YData (1,:) double = NaN LineColor (1,3) double {mustBeGreaterThanOrEqual(LineColor,0),... mustBeLessThanOrEqual(LineColor,1)} = [.5 0 1] end properties(Access = private,Transient,NonCopyable) CartesianLine (1,1) matlab.graphics.chart.primitive.Line PolarLine (1,1) matlab.graphics.chart.primitive.Line CartesianAx (1,1) matlab.graphics.axis.Axes PolarAx (1,1) matlab.graphics.axis.PolarAxes end
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);
end
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;
end
end
end
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:2pi; y = sin(2x).cos(2x); CartPolarPlot('XData',x,'YData',y);
Version History
Introduced in R2020a