First, we will introduce the content of objects and handles.
MATLAB calls each basic element of a graph as a graph object. When every graph object is generated, Matlab automatically assigns a unique value to indicate this object, which is called a handle.
Basic Relationship between objects:
Computer Screen-> graphic window-> (User menu, user control, axis)
Axis> (curve, surface, text, image, light source, area, box)
Basic underlying plotting functions:
Line object and line function
H = line ('pro1', 'val1 ',
'Pro2', 'val2 ',...);
For example, the following function:
H = line ([-Pi: 0.01: Pi], sin ([-Pi: 0.01: Pi]); % is equivalent to HP = plot ([-Pi: 0.01: pi], sin ([-Pi: 0.01: Pi]);
After running, the system will generate:
Generate line object. H is the line object handle;
Line object modification:
Color Attribute;
Linewidth attribute;
Linestyle attribute;
Marker attributes;
Markersize attribute;
The plot drawn by plot is also a line object, which can be modified later by using the line Object modification method.
You can draw a curve and define relevant attributes as follows:
hl = line('XData', [-pi:0.1:pi], 'YData', sin([-pi:0.1:pi]), ... 'LineWidth', 1, 'LineStyle', ':', 'Color', 'r');
If this does not fully meet our requirements, we can use set to modify attributes:
hl = line('XData', [-pi:0.1:pi], 'YData', sin([-pi:0.1:pi]), ... 'LineWidth', 1, 'LineStyle', ':', 'Color', 'r');set(hl, 'LineWidth', 2, 'Marker', 'p', 'MarkerSize', 15);
Next, let's take a look at the underlying tagging operations:
Text object and text function.
We can use the text function to return a handle value.
Modifier:
Color Attribute
String attribute
Fontsize attribute
Rotation attributes
hl = line('XData', [-pi:0.1:pi], 'YData', sin([-pi:0.1:pi]), ... 'LineWidth', 1, 'LineStyle', ':', 'Color', 'r');set(hl, 'LineWidth', 2, 'Marker', 'p', 'MarkerSize', 15);ht = text(0, 0, 'sin');set(ht, 'String', 'cos');set(ht, 'FontSize', 20);
The effect is as follows:
Next, let's take a look at the problems related to the coordinate axis.
Axes object and axes Function
Axis attribute modification:
Box attribute
Gridlinestyle attributes
Position attribute
Units attributes (common)
Xlabel, ylabel, and zlabel attributes
Xlim, ylim, and zlim attributes
If the unit attribute of the axis is not set to normalization at the beginning, the default axis attribute is normalized.
We can use the figure function for demonstration. The Unit attribute is changed to pixels by default.
However, when the window is changed, the size of the window changes greatly. Therefore, normalized is recommended.
hf = figure;ha = axes('Parent', hf, 'Units', 'normalized', 'Position', [.1 .1 .6 .5]);
Effect after running: