Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.


dpb
Posts:
8,571
Registered:
6/7/07


Re: Changing a color of a line after being plotted
Posted:
Jul 3, 2013 1:11 PM


On 7/3/2013 11:06 AM, P.O.L. wrote: > Hi, > > I'm a bit of a novice. How do you change the color of a plotted line > after being plotted? > i.e. figure; plot(x1, y1, x2, y2, x1, y3, x1, y4, 'LineWidth',2) > > The plot comes up with 4 curves (all different colors), but I'd like to > mess around with different colors for specific lines after plotting. > > Is there a useful plot documentation out there? I'm having trouble > plotting things "quickly" and find myself having to redo plots > completely if I forget to something ahead of time (because I'm having > trouble changing properties after plotting).
You use getset to change properties of graphics objects. See the documentation on them and there are multiple examples in the graphics sections of all kinds of things that can be done.
One really good "trick" to learn is that of
get(gca)
will return a list of all the properties/values of the current axes object (gca) so you can get the property names right there when can't recall/don't know which it is you want.
If you're wont to modify plots (and who amongst us isn't :) ), you'll find it worthwhile to get in habit of saving handles for those things you're likely to want to modify if it's more than just the axes propertiesif not, while there is gca for the axes object, the others then have to be obtained from a (perhaps iterative) call to get(gca,'children') and then find and use the appropriate one of those handle(s).
PLOT, in particular, returns the handles of the lines in a column vector if you use the form
hL=plot(...);
and then you can directly access the line properties using those handles if you saved themif not, then as above you have to go get them first (or, of course, use the interactive tools on the figure itself or the like).
Read the "Getting Started" on graphics thru at least quickly to get an idea of how handle graphics work...




