Add legend, title, and color to figure in MATLAB)

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.