The File Exchange a Pick of the Week

Our best user submissions

Programmatically adding data tips

Richard is Consulting Engineer at MathWorks focused on the Embedded Coder product for code generation, primarily in the Aerospace industry.

Richard 'sPick this week isadd_Data_TipsbyMassimo Ciacci.

Contents

Pick

My pick this week by the utility functionadd_Data_TipsTips for programmatically adding data to multiple lines in a plot.

If you write custom scripts/functions provides the to plot the data it is, beneficial to highlight specific points in the plot to the as minimums/maximums.DatatipsAllow you to show the values of the data at selected locations in the figure.

While you can add data tips to plot a manually, it is about the add data tips to multiple lines at the same location on the X axis.add_Data_TipsSolves this problem. Using add_Data_Tips, you can insert data tips on multiple lines in a plot at a specified X axis locations. For instance, if you want to call out the maximum value of a plot, you can use theMaxFunction to find the index of the maximum value of the Y - Axis data and specify the corresponding X Axis data in the call toadd_Data_TipsTo insert a data tip in the figure at the maximum point.

N = 0:50;Y = cos (. 5 * (n)). ^ 3 + sin (. 3 * (n)) ^ 2;Figure yh = plot (n, y);[~, indx] = Max (y);Add_DataTips (n (indx), yh, 7)

If you have a figure with multiple plots, and tips you can add the data to any or all of the lines at the same X Axis location by passing in the handles to the desired lines.

N = 0:50;Y = cos (. 5 * (n)). ^ 3 + sin (. 3 * (n)) ^ 2;Figure yh (1) = plot (n, y);holdonY2 = sin (1.5 x (n)). ^ 3 - cos (1.3 x (n)) ^ 2;Yh (2) = plot (n, y2);[~, indx] = Max (y);Add_DataTips (n (indx), yh, 7)

If you already have a plot, you can get the handles to the lines by accessing the Children of the axes

CurrentAxes = "gca";LinesHandles = CurrentAxes. Children;X_location = 10;Add_DataTips (x_location LinesHandles, 7)

You can use the examples above or the File Exchange submission includes a demo script, 'test_add_DataTips. M', that provides an example.

New in R2019b

If you have access to the most recent release, R2019b, you can now programmatically create datatips using the newdatatipThe function.

Figure yh = plot (n, y);[~, indx] = Max (y);The datatip (yh,'DataIndex', indx);

Comments

It a boost by the and let us know what you thinkhereOr leave aThe commentFor Massimo.




Published with MATLAB ® R2019b

|
  • The print
  • Send E-mail.

comments

To comment, please clickhereLog in to your MathWorks account or create a new account.