How to remove labels from a plot?
Mostra commenti meno recenti
Goodnight. I ask for your help with a new problem. I am having problems with the removal of labels in a graph. What happens is that I have a matrix (of 3 columns) called "Nodes_et" that carries the x-y coordinates in its first 2 columns, while in the third it is named after the point to which those coordinates correspond. I have these lines of code that are helping me to generate and position the labels correctly (I leave part of the code and some images to better understand the situation I commented):
Nodos_et=unique(Nodos_et,'rows');
eti=text(Nodos_et(:,1)+0.1,Nodos_et(:,2)+0.1,num2cell(Nodos_et(:,3)) );
hold on;


As you observed the code fulfills its function, however I need to remove certain labels (depending on a condition that I have programmed) and I can not do them. Try reassigning the "Nodes_et" matrix to the values you wanted to label, for example, the values that the matrix carried minus the one in the second row remain, assuming this would eliminate the label that was in that second row, but it didn't work:
hold off;
Nodos_et(2,:) = [];
eti=text(Nodos_et(:,1)+0.1,Nodos_et(:,2)+0.1,num2cell(Nodos_et(:,3)) );



remains the same

Can anyone help me with this problem? Thank you.
6 Commenti
Rik
il 8 Ago 2019
You mean you want to remove some of the numbers you're creating with the text function?
Pedro Guevara
il 8 Ago 2019
Maybe I'm not understanding the quesiton but why can't you just comment-out (or delete) the text() functions that are writing the labels in the first place?
If you need the labels temporarily, you can delete them using their handles.
th = text(. . .)
delete(th)
Adam
il 8 Ago 2019
Always keep hold of the handles to the graphics objects you create if you think you will later want to edit them in some way, it is a lot easier than messing around with having to find them again afterwards.
As Adam Danz says though you have to explicitly delete text objects, you can't just call text again with fewer elements and expect that it will replace all the ones you did previously with the new smaller list.
Pedro Guevara
il 8 Ago 2019
Modificato: Pedro Guevara
il 8 Ago 2019
Adam Danz
il 8 Ago 2019
I included an answer that shows how to store text object handles and how to delete them. You'll have to make some design decisions about how to best organize your code so you can keep track of which handles are associated with which rows of your UITable. That shouldn't be a problem. It looks like lines are also created/deleted based on the rows of your UITable. Text objects will work the same way as the lines.
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Labels and Annotations in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!












