Can you detect when a title is added to a plot?
Ältere Kommentare anzeigen
I have a GUI where a single figure has multiple pannels. Graphs can be added to these panels at any unknown time by a user. I want to populate a popup menu with the titles of graphs (axes) as they are added to these panels by the user. User population is to work the same as adding a plot to a standard figure in that after creating the figure, the code really has no idea at what point the user will add the plot and the title so there is no post add title point at which to pull the title. It would instead need to be able to react to the title being added. I have tried manualy creating a blank axes on the panel for which the user will plot to next so that the next plot is directed there and attached a propertly listerer to the string property of the title object of the axes. This should work except that it doesnt due to new plots to an existing axes result in the old axes title being deleted in the background with no clear way to find the handle to the new title. Any ideas on a good way to do this?
7 Kommentare
Jan
am 27 Feb. 2019
What exactly is a "Graph" and how does the user add it? Would it be easy to create a button called "Add Graph" and insert some code inthe callback, which delivers the title to where it is needed? I'd recommend to avoid relying on magic side-effects and an automatic recognition. A straight-forward well defined way is smarter.
On the other hand, it should be easy to check all panels for included titles automatically. If you provide some code to create a minimal working example, it is much easier to suggest the needed additions.
Dan
am 27 Feb. 2019
Dan
am 27 Feb. 2019
Dan
am 27 Feb. 2019
Walter Roberson
am 27 Feb. 2019
I should further add that the point of my GUI is to completely replicated the functions of a standard matlab figure but instead do it with multiple panels inside a single figure such that each panel is to behave as a standalone matlab figure would (which I have working).
Ummm, it seems unlikely that you have it fully working. Standard MATLAB figures are not just graphics containers: figures also have behavior associated. For example, bode() forces the behaviour for the figure to change, and it does so in a way that is not compatible with having multiple panels each with different behaviour.
There is a way to do it in MATLAB, using routines that have little documentation, but you would have mentioned those if you were using them, as they have a bunch of complications.
Dan
am 27 Feb. 2019
Dan
am 27 Feb. 2019
Akzeptierte Antwort
Weitere Antworten (1)
Sean de Wolski
am 27 Feb. 2019
If the axes already exists, this seems to work
ax = axes
addlistener(ax.Title,'String','PostSet',@(~, ~)disp('hi'))
title('Hello World')
Now just change the listener callback to fire an update of your listbox.
7 Kommentare
Dan
am 27 Feb. 2019
Jan
am 27 Feb. 2019
What about:
ax = axes('NextPlot', 'add');
addlistener(ax.Title,'String','PostSet',@(~, ~)disp('hi'))
surf(peaks)
title('Hello World')
Dan
am 27 Feb. 2019
@Dan: I understand. Is it really required to let the creation of a title trigger the event? What about letting the popup menu collect all existing titles dynamically before the menu is displayed? Then you do not need an additional method to handle deleted titles or axes.
Dan
am 27 Feb. 2019
Jan
am 28 Feb. 2019
@Dan: I've done equivalent things in the Matlab level by creating an 'Enable'='inactive' element and let its ButtonDownFcn (not the Callback) trigger the automatic collection of data. Then instead of a popup menu I show a UIContextMenu at the same position, because I can set its Visible status dynamically to let it appear as if it was an activated popup menu. Not nice to write, but looks fine and I have all functionality, where it is needed. The user can do, whatever he wants, because the pseudo-popup keeps the power of finding, what it is needed.
Of course I do like the idea of letting new objects send a message which allows to identify them. But as long as Matlab is not completely object oriented and the plot command is inherited from the current figure automatically, such that you can define figure depended modifications directly, I prefer the active collection instead of a message passing.
Dan
am 28 Feb. 2019
Kategorien
Mehr zu 2-D and 3-D Plots finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!