How to add information in a figure already created
15 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
German Preciat Gonzalez
am 5 Okt. 2017
Bearbeitet: German Preciat Gonzalez
am 28 Nov. 2017
Imagine that I have a function like this
function somethingPlotted = plotSomething(x, y)
somethingPlotted = plot(x,y);
end
if I write this:
x = 0:pi/100:2*pi;
y = sin(x);
somethingPlotted = plotSomething(x, y)
my out put will be:
somethingPlotted =
Line with properties:
Color: [0 0.4470 0.7410]
LineStyle: '-'
LineWidth: 0.5000
Marker: 'none'
MarkerSize: 6
MarkerFaceColor: 'none'
XData: [1×201 double]
YData: [1×201 double]
ZData: [1×0 double]
Show all properties
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/167900/image.jpeg)
How can I modify the variable somethingPlotted in order to change the axis, adding legend, and adding more plots with different color in somethingPlotted?
What I really need is to go from here
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/167901/image.png)
to here
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/167902/image.png)
By modifying somethingPlotted
thanks in advance!
Regards!
0 Kommentare
Antworten (1)
KL
am 5 Okt. 2017
Bearbeitet: KL
am 5 Okt. 2017
If this plot is the current figure then use gca, gcf. Even better is to output the axes and figure handle from your plotSomething function. For example,
[somethingPlotted, ax, fig] = plotSomething(x, y)
ax.Title.String = 'My Title';
1 Kommentar
Steven Lord
am 5 Okt. 2017
If all you have is the handle to the line, instead of using gca or gcf in a function I would use ancestor. This will ensure you get the axes or figure in which that line is located, not the last one on which the user clicked.
h = plot(1:10)
ax = ancestor(h, 'axes')
f = ancestor(h, 'figure')
f2 = figure;
isequal(gcf, ancestor(h, 'figure')) % false
% Changing gcf's Color makes f2 cyan
set(gcf, 'Color', 'c');
% Changing h's figure ancestor makes f black
set(ancestor(h, 'figure'), 'Color', 'k')
Siehe auch
Kategorien
Mehr zu Annotations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!