This is because a legend in itself is basically an axes object. You can add any figure's child with the DisplayName property to any legend in the figure, e.g. The legend updates automatically if an object is added or removed from its PlotChildren property.ġ Indeed: figure. L.PlotChildren(end + 1) = hTan % Append the graphics handle to legend's plot children To control the appearance of legend entries, plot points that have values which are NaN then pass the objects returned by plot and an array of labels to the legend function (NaN points are not visible in the plot, but appear in the legend). So, the way to go is to explicitly set the legend's children through its PlotChildren property as follows: hTan.DisplayName = 'tangent' % Set the graphics object's display name Luckily, an undocumented legend property called PlotChildren keeps track of the children of the parent figure 1. Legend sine '' tangent % Sets cos DisplayName, albeit empty -> fail Legend sine tangent % Sets cos DisplayName to 'tangent' -> fail Legend -DynamicLegend % Undocumented feature, adds 'cos', which shouldn't be added -> fail Now, to add a legend entry for tan, but not for cos, any of the following lines won't do the trick they all fail in some way: legend tangent % Replaces current legend -> fail HTan = % Make sure to get the handle, hTan, to the graphics object you want to add to the legend Hold sin % Add only a legend entry for sin For example, if your plot has two lines, but only one of them has a legend entry and that should stay this way, then adding a third line with a legend entry can be difficult. Semi-transparent markers in line and scatter plotsĮxisting legends can be difficult to manage.Contour Plots - Customise the Text Labels.Color-coded 2D line plots with color data in third dimension.Appending / adding entries to an existing legend.Ordinary Differential Equations (ODE) Solvers.Fourier Transforms and Inverse Fourier Transforms.*Note: I've read similar questions but can't still make it work given that I'm plotting four y lines using a single plot() function. How can I append the legend to the already existing legend, instead of just replacing it? However, if the for loop happens more than once, the new legend does not append to the existing legend. If the for loop happens only one time, then I can easily add a legend using the legend() function. I have a for loop that looks somewhat like these: RowToPlot =2 Įach plot line plots 4 lines in the y axis, and depending on the value in Num, the for loop could repeat and more lines could be plotted.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |