'via Blog this'
MATLAB Hints and Tricks #2
Handle Graphics: Getting a grip on your pictures
Wouldn't you like some control over the details of your MATLAB plots? Sometimes when you create a plot and want to convert it to a "gif" file, print it onto a transparency, or make a figure for a paper, you'd like to control the font size or line thickness. Here are a few tips on how to do this.
The MATLAB graphics system is a "handle graphics" system. This is actually a fairly common programming technique, used by Microsoft Windows programmers as well as X windows. What happens is that when you create a graphic, MATLAB returns a number (or vector of numbers) which are "handles" to the graphic(s). You use these handles to make requests to MATLAB to "get" or "set" certain characteristics. For example, if you were to plot a couple of lines on your graph, and you want to change their color and thickness, you'd do the following:
x=[0:.1:20]; % an example x variable y1=sin(x); y2=cos(x); % example y variables h=plot(x,y1,x,y2); % plot both variables, returns two numbers in h set(h,'LineWidth',2); % set both lines to 2 pixels wide set(h(2),'Color','Green'); % change 2nd line to green set(h(1),'Color','Red',LineWidth,4); % change 1st to red, and even thicker!
No comments:
Post a Comment