![]() ![]() The resulting plot would be the same as the first example shown earlier in the tutorial. The legend would then be toggled on by calling legend() without any input arguments. % Plot the lines h1 = plot( x, sin( x ), 'rx', 'linewidth', 2, 'DisplayName', 'Line1' ) hold on h2 = plot( x, cos( x/3 ) - 0.25, 'bs', 'linewidth', 2, 'DisplayName', 'Line2' ) h3 = plot( x, cos( 4*x )/3, '^g', 'linewidth', 2, 'DisplayName', 'Line3' ) hold off % Update the display names set( h1, 'DisplayName', 'Line1' ) set( h2, 'DisplayName', 'Line2' ) set( h3, 'DisplayName', 'Line3' ) The syntax for the set() should like this. The syntax for the plot() should look like this. In both cases, after you have set the properties, you need to all legend() without any arguments to toggle the legend on. This can be done during the plot() call or using set() on the handle. ![]() Image by author Using the “DisplayName” PropertyĪnother convenient way to add the legend labels is to set the “DisplayName property on the lines as they are plotted. legStr = legend( legStr ) įor convenience, this method will be used for the rest of the examples. This is most useful when you are programmatically creating the legend string. In addition to specifying the labels as individual character strings, it is often convenient to collect the strings in a cell array. x = 0 : 0.1 : ( 2pi ) plot( x, sin( x ), 'rx', 'linewidth', 2 ) hold on plot( x, cos( x/3 ) - 0.25, 'bs', 'linewidth', 2 ) plot( x, cos( 4x )/3, '^g', 'linewidth', 2 ) hold off xlim( ) grid on title( 'Sample Plot' ) set( gca, 'fontsize', 16 ) Ī legend can be added with the following command. The basic syntax is: legend( ‘Description 1’, ‘Description 2’, … ).įor the examples in this section, we will generate a sample figure using the following code. ![]() The simplest way to use the function is to pass in a character string for each line on the plot. The legend() function in MATLAB/Octave allows you to add descriptive labels to your plots. The source code for the included examples can be found in the GitHub repository. In this article, I cover the basic use of the legend() function, as well as some special cases that I tend to use regularly. Luckily, MATLAB/Octave include the legend() function which provides some flexible and easy-to-use options for generating legends. The codes and data files for the book are available on Github and on Springer Link.Plot legends are essential for properly annotating your figures. Special attention is given to the methods of linear and nonlinear regression. The high level tool Matlab/Octave is used to develop computational code for micro controllers. A selection of typical, independent engineering problems is presented, together with algorithms to solve these problems. It is shown how basic statistical questions can be answered and how results are visualized using appropriate types of graphical representation. The selection of the presented commands is guided by the typical needs of engineers. With these skills many and more difficult problems can be solved successfully. Basic data and programming structures are presented and for the most often used commands illustrative code samples are provided. This book will help the reader to acquire basic knowledge and elementary programming skills with Octave/Matlab. The well established Matlab and Octave (a very similar open source software) are excellent tools for modeling, computing and visualization. For many engineering tasks extensive computations or visualizations are required. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |