Cannot delete text added to scatter plot points (2024)

16 views (last 30 days)

Show older comments

Matt on 30 Jul 2015

  • Link

    Direct link to this question

    https://matlabcentral.mathworks.com/matlabcentral/answers/231762-cannot-delete-text-added-to-scatter-plot-points

  • Link

    Direct link to this question

    https://matlabcentral.mathworks.com/matlabcentral/answers/231762-cannot-delete-text-added-to-scatter-plot-points

Edited: dpb on 30 Jul 2015

Open in MATLAB Online

Hello!

I have an issue regarding TEXT items. I have a scatter plot which works fine, then I am adding to the points some simple labels using the TEXT function. It works fine, but at some point I want to update the plot which means items are removed from the scatter plot.

When I use the TEXT function again, it adds labels to the updated points, but keeps the old text in place. There is no point on the graph because it has been deleted, but the label remains although obsolete.

Using the DELETE function didn't solve the issue.

Here is my code for the scatter plot and the text labels:

set(panel3.pl1, 'XData', pointM(:,1), 'YData', pointM(:,2), 'SizeData', sizedata, 'CData', colordata);

legend1=text(pointM(:,1), pointM(:,2), c, 'Color', 'g', 'FontWeight', 'bold');

Then what I am doing is just deleting the legend1 item using a pushbutton, but it doesn't work.

Any clue?

1 Comment

Show -1 older commentsHide -1 older comments

dpb on 30 Jul 2015

Direct link to this comment

https://matlabcentral.mathworks.com/matlabcentral/answers/231762-cannot-delete-text-added-to-scatter-plot-points#comment_301162

  • Link

    Direct link to this comment

    https://matlabcentral.mathworks.com/matlabcentral/answers/231762-cannot-delete-text-added-to-scatter-plot-points#comment_301162

If it's in a GUI; I'm guessing that most likely problem is that you haven't passed the handle legend1 in a way such that it is available to the GUI. What does "doesn't work" mean, precisely? IOW, what error or other symptoms are there? Have you used debugger to step thru the callback function?

Sign in to comment.

Sign in to answer this question.

Answers (2)

Star Strider on 30 Jul 2015

  • Link

    Direct link to this answer

    https://matlabcentral.mathworks.com/matlabcentral/answers/231762-cannot-delete-text-added-to-scatter-plot-points#answer_187700

  • Link

    Direct link to this answer

    https://matlabcentral.mathworks.com/matlabcentral/answers/231762-cannot-delete-text-added-to-scatter-plot-points#answer_187700

Open in MATLAB Online

I don’t know what about delete didn’t work for you, since we don’t have enough of your code to experiment with it.

For an example, see if this (archive) code snippet (that deletes the label for point 10) suggests a solution:

N=20;

area=100;

X=rand(1,N)*area;

Y=rand(1,N)*area;

for i=1:N

hp(i) = plot(X(i),Y(i));

ht(i) = text(X(i),Y(i),num2str(i),'fontsize',10);

hold on

end

XY=[X;Y]';

Q10 = XY(10,:); % Get Coordinates Of Point To Be Deleted

delete(hp(10)) % Delete Plotted Point

delete(ht(10)) % Delete Text Label

2 Comments

Show NoneHide None

Muthu Annamalai on 30 Jul 2015

Direct link to this comment

https://matlabcentral.mathworks.com/matlabcentral/answers/231762-cannot-delete-text-added-to-scatter-plot-points#comment_301180

  • Link

    Direct link to this comment

    https://matlabcentral.mathworks.com/matlabcentral/answers/231762-cannot-delete-text-added-to-scatter-plot-points#comment_301180

Open in MATLAB Online

I was going to add the following comment, but it is superfluous in the light of relativity of simultaneity ... :-)

@Matt, @dpb - I wonder if you make the figure current via

fig_handle = scatter(...)

figure(fig_handle)

delete(txt_handle)

it should be able to delete the object.

dpb on 30 Jul 2015

Direct link to this comment

https://matlabcentral.mathworks.com/matlabcentral/answers/231762-cannot-delete-text-added-to-scatter-plot-points#comment_301195

  • Link

    Direct link to this comment

    https://matlabcentral.mathworks.com/matlabcentral/answers/231762-cannot-delete-text-added-to-scatter-plot-points#comment_301195

Edited: dpb on 30 Jul 2015

Whether the figure is in focus or not makes no difference; the handle refers to the object directly without reliance on any other hierarchy.

I don't follow at all why OP would think there's even any possibility he can delete the object using its handle if he doesn't pass that handle to a new scope (the second button's callback function that tries to do the dirty).

Sign in to comment.

Matt on 30 Jul 2015

  • Link

    Direct link to this answer

    https://matlabcentral.mathworks.com/matlabcentral/answers/231762-cannot-delete-text-added-to-scatter-plot-points#answer_187701

  • Link

    Direct link to this answer

    https://matlabcentral.mathworks.com/matlabcentral/answers/231762-cannot-delete-text-added-to-scatter-plot-points#answer_187701

Edited: Matt on 30 Jul 2015

Basically I have 1 pushbutton that adds points to the pointM matrix, as well as the color and size parameters for the scatter plot, and then another pushbutton that remove points from that pointM matrix. I can successfully see the points being added and removed from the scatter plot.

When I add points, the labels are added accordingly which is good, and when I remove points, the labels are updated accordingly.

Thing is that when some points are deleted, the labels are not so I end up having labels next to nothing as the point has been deleted.

I shouldn't have to pass the legend1 text handle from one button to the other since I just want to delete it and then re-create it.

Hope it helps!

1 Comment

Show -1 older commentsHide -1 older comments

dpb on 30 Jul 2015

Direct link to this comment

https://matlabcentral.mathworks.com/matlabcentral/answers/231762-cannot-delete-text-added-to-scatter-plot-points#comment_301175

  • Link

    Direct link to this comment

    https://matlabcentral.mathworks.com/matlabcentral/answers/231762-cannot-delete-text-added-to-scatter-plot-points#comment_301175

Edited: dpb on 30 Jul 2015

"... 1 pushbutton that adds points ... then another ... that remove[s] points...I shouldn't have to pass the legend1 text handle from one button to the other since I just want to delete it ..."

How is the delete button to know what to delete and get access to it if it doesn't have the handle? Of course you have to pass it (or have access to it by some other method such as (ugly) making it global).

ADDENDUM

OK, there is a way other than passing; use findobj or similar technique in the "delete" callback routine to uncover the handle of the desired text object. This'll entail having some way to ascertain "who's who in the zoo" of all the possible text entities that may be present to make sure it's the right one (like keeping a tag or somesuch).

But, however you do it, you must somehow have the handle associated with the specific text object you wish to remove in the context of the function doing the deleting. That you make it in some other function is immaterial once you leave that function you're operating in a new scope and any and everything that was defined inside that function is gone when you leave unless it was made persistent or you passed it back out as a return value or made it global (again, Ugly!) or whatever...

Sign in to comment.

Sign in to answer this question.

See Also

Categories

MATLABGraphicsFormatting and AnnotationLabels and AnnotationsAnnotations

Find more on Annotations in Help Center and File Exchange

Tags

  • scatter
  • delete
  • label

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


Cannot delete text added to scatter plot points (8)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Contact your local office

Cannot delete text added to scatter plot points (2024)

References

Top Articles
CUNY Among Prime Partners of Cyber NYC, Initiative Pairing Colleges With Industry to Create Major Hub of Learning, Innovation in Emerging Field – The City University of New York
Here Are The Colleges With The Most 2024 Olympic Medals—And What To Know About Them
Ink Free News Kosciusko County
Nambe Flatware Discontinued
Msc Open House Fall 2023
Spectrum Store Kansas City Photos
Fbsm Berkeley
Solo Player Level 2K23
Cbs Week 10 Trade Value Chart
Chukchansi Webcam
Trey Yingst Parents Nationality
KMS ver. 1.2.355 – Haste & Tactical Relay
Santa Cruz Craigslist Cars And Trucks - By Owner
Finger Lakes 1 Police Beat
Syoss Oleo Intense - 5-10 Cool Bruin - Permanente Haarverf - Haarkleuring - 1 stuk | bol
Die 12 besten Chrome Video Downloader im Überblick
Cosmoprof Jobs
Frontier Channel Lineup Dallas
April 7 Final Jeopardy
Six Oaks Rv Park Mooresburg Tn
Downloahub
Gw2 Titles
Hannaford Weekly Flyer Manchester Nh
Peoplesoft Oracle Americold Login
Monkey Werx Sitrep 2022
Cognitive Function Test Potomac Falls
Eddy Ketchersid Obituary
3 Hour Radius From Me
1946 Chevy Truck For Sale Craigslist
Doculivery Trinity Health
Ts Central Nj
Adams County 911 Live Incident
The Ultimate Guide To Kaitlyn Krems Of
Game Akin To Bingo Nyt
Februarycash2023
Is Glassagram Illegal
Sierra Vista Jail Mugshots
What Was D-Day Weegy
Limestone Bank Hillview
Pensacola Tattoo Studio 2 Reviews
Alylynn
The Spot Barbershop - Coconut Creek Reviews
Amariah Morales Snapchat
Abq Pets Craigslist
Jefferey Dahmer Autopsy Photos
Mnps Payroll Calendar 2022-23
'Selling Sunset' star Alanna Gold said she owned a California desert town. Now, she says she doesn't.
Grayson County Craigslist
Corn And Tater Fest 2023
Jili Game Cityjili
Chirp One Medical Seniors
Milly Bobby Brown Nsfw
Latest Posts
Article information

Author: Delena Feil

Last Updated:

Views: 6180

Rating: 4.4 / 5 (45 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Delena Feil

Birthday: 1998-08-29

Address: 747 Lubowitz Run, Sidmouth, HI 90646-5543

Phone: +99513241752844

Job: Design Supervisor

Hobby: Digital arts, Lacemaking, Air sports, Running, Scouting, Shooting, Puzzles

Introduction: My name is Delena Feil, I am a clean, splendid, calm, fancy, jolly, bright, faithful person who loves writing and wants to share my knowledge and understanding with you.