There are also entire semi-documented functions: many of the uitools (e.g., uitree, uiundo), as well as hgfeval and others. Some other examples, which I may cover in future posts, include text(…, ‘sc’), drawnow( ‘discard’), several options in pan and datacursormode etc. Even my reported workaround in January this year went unanswered (no hard feelings…).ĭynamicLegend is a good example of a useful semi-documented feature. This feature has existed many releases back (Matlab 7.1 for sure, perhaps earlier), so while it may be discontinued in some future Matlab release, it did have a very long life span… The down side is that it is not supported: I reported the bar/stairs issue back in mid-2007 and so far this has not been addressed (perhaps it will never be). It is an unsupported feature originally intended only for internal Matlab use (which of course doesn’t mean we can’t use it). This means that the feature is explained in a comment within the function (which can be seen via the edit( ‘legend’) command), that is nonetheless not part of the official help or doc sections. The DynamicLegend feature is semi-documented. – object visibility in the legend can be controlled on an object-by-object basis using the semi-documented hasbehavior function. My fix solves this, but I do not presume this solves all possible problems in all scenarios (please report if you find anything else). The origin of the bug is that bar and stairs generate hggroup plot-children, which saves the legend strings column-wise rather than the expected row-wise. To temporarily disable the DynamicLegend listener, do the following: For example, in my GUI I needed to plot several event lines which looked alike, and so I only wanted the first line to be added to the legend. You can add text-box annotations in a figure using the annotation function as follows: annotationObj annotation ('textbox', 0.3 0.3 0.12 0.08,'String',Some text') You can also provide the figure handle (gcf, or.
You can leave a response, or trackback from your own site. You can follow any responses to this entry through the RSS 2.0 feed. This entry was posted on Wednesday, November 16th, 2011 at 4:44 am and is filed under code. It is sometimes necessary to selectively disable the dynamic behavior. I understand that you want to provide additional information on your plot in a text-box like element. Tags: figure, legend, matlab, newline, string. We can see how the dynamic legend automatically keeps in sync with its associated axes contents when plot lines are added/removed, even down to the zoom-box lines… The legend automatically uses the plot lines ‘DisplayName’ property where available, or a standard ‘line#’ nametag where not available:ĭynamicLegend works by attaching a listener to the axes child addition/deletion callback (actually, it works on the scribe object, which is a large topic for several future posts). Hold all % add new plot lines on top of previous ones 3,609 1 1 gold badge 28 28 silver badges 38 38 bronze badges. Hold all % add new plot lines on top of previous ones plot (x, cos (x ), 'DisplayName', 'cos' ) That way, at the second iteration the plot from the 2nd iteration will be plotted, the plot from the 1st will be deleted and after these operations I get it to display the plot (again drawnow).Plot (x, sin (x ), 'DisplayName', 'sin' )
I delete h_old and overwrite it with the new plots I created. Second Plot (in the called function) h(1)=plot(points,modeldata1,'r-','DisplayName','Model Data, L= 0.1 m') I chose 0,250 because it's in the range of the data (otherwise it messes up the axis) Legend('-DynamicLegend','Location','Best')ĭrawnow forces the plot to be drawn right away, and h_old is just a "placeholder" that I make use of later on. Plot(points,expdata3,'go','DisplayName','Experimental, L= 0.3 m')
Plot(points,expdata2,'bo','DisplayName','Experimental, L= 0.2 m') I was able to do it with a combination of solutions from different questions.Ĭlose all will ensure your plot starts anew every timeįirst plot (in my main) plot(points,expdata1,'ro','DisplayName','Experimental, L= 0.1 m') hold on I had a similar issue: I plotted three sets of experimental data first, then got into my parameter estimation to simulate the function and wanted to plot the model data every time, holding on to the experimental data but deleting the model data from the previous run.