In the process of MATLAB drawing, especially when multiple graphs need to be drawn in the same coordinate axis, different curves usually need to be set to different colors. In addition, you need to add titles and legends to the icon to make it intuitive. This article shows how to set the curve color, add a legend (LEGEND), and title (title) in the graph window of Matlab.
In Matlab, the plot function can be used to set the color of the curve. In the following statement: plot (X, Y, 'R'), the red curve is drawn based on the X variable as the abscissa, And the y variable as the ordinate. Here, color control is implemented by 'R. In Matlab, seven colors are prefixed, namely 'R' 'G' 'B' 'C' m' 'y' K '. If you need more color adjustments, you can use the 'color' keyword. The syntax is as follows: plot (X, Y, 'color', [0.1 0.2 0.3, the matrix that appears after the 'color' keyword controls the color of the drawn image. After a curve is drawn, you can use the title function to add a title to the drawing. The specific code format is as follows: figure; plot (X, Y, 'R') Title ('this is the curve you have drawn '); in addition, when drawing multiple curves, to differentiate curves, you also need to add legends, which can be implemented using the legend function. The code format is as follows: figure; plot (X, Y, 'R') legend ('this is the legend you need '); finally, the following code demonstrates all the above functions, as shown in: figure; plot ([], []); Title ('this is the title '); hold on plot ([], [], 'color', [0.1 0.7 0.3]); hold off legend ('line 1', 'Line 2 '); the running result is as follows:
Add legend, title, and color to figure in MATLAB.