Overwrite data in figure but keep axis labels, title, and legend
Ältere Kommentare anzeigen
Hi,
I would like to overwrite only the data presented in a figure while keeping the labels and legends the same. I do not want to waste space and time on re-labeling the figures. 'hold on' holds the plot but does not overwrite the existing data and only adds to it.
Thank you for your help.
Akzeptierte Antwort
Weitere Antworten (2)
Jack LeBien
am 6 Aug. 2016
Hi, you can use
hold on
cla
plot(newData)
cla (clear all) will remove the plotted data but not other formatting.
7 Kommentare
Alexei M
am 8 Aug. 2016
That doesn't solve the OP's problem. I just tried this (because I have the exact same question as OP), but when you subsequently use the plot command again, it removes the axis labels and etc. The goal here was to preserve the other formatting but "refreshing" the plotted data to something else.
Jack LeBien
am 12 Aug. 2016
Bearbeitet: Jack LeBien
am 12 Aug. 2016
I didn't have that issue. If I have a figure with certain labels and other formatting active, then set hold on, cla will then clear the plotted data, leaving labels etc. Then plot will fill the plot without clearing the formatting. Did you make sure to have hold on?
David Walwark
am 1 Dez. 2018
I did this technique helpful, thanks.
Ruby Singh
am 2 Dez. 2018
wow this is the most simple way to solve my similar problem!
thanks !!!!!!!!!!!!
Dyl
am 19 Dez. 2019
This should be the accepted answer.
rzehumat
am 4 Jan. 2021
+1 Dyl, I think as well that this one should be accepted.
Keyur Panchal
am 9 Mär. 2021
Thanks!!
using cla instead of clf works well
MechtEngineer
am 8 Apr. 2014
Bearbeitet: John Kelly
am 31 Okt. 2022
I don't see how the previous answer keeps the axis labels, title and legend when plotting some new data on the same axis.
The code that worked for the author (and for me) was:
title('Some Title','HandleVisibility','off');
ylabel('Some ylabel','HandleVisibility','off');
xlabel('Some xlabel','HandleVisibility','off');
set(gca,'NextPlot','replacechildren') ;
Any subsequent plots on this axes keeps the existing axes properties (including title, axis labels and legend), while replacing child objects (e.g. data)
2 Kommentare
jinsong mao
am 5 Sep. 2017
this method proves to be good, which can solve my problem, i want to keep the label in matlab gui while ploting in callback functions. thanks guys
jinsong mao
am 5 Sep. 2017
tried only set(gca,'NextPlot','replacechildren') ; works good too
Kategorien
Mehr zu Labels and Annotations finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!