Description: Clean up and save plots. Configure axis labels. Call another script (plotdefaults.m) within fitting.m. Get Octave help with 'doc' command. Using comments in scripts. Save plots with the 'print' command.
Instructor: Prof. Ian Hutchinson
IAN HUTCHINSON: Let's just finish this off by cleaning up this plot and saving it. In the first case, I don't have any labels on my axes. That's bad. Let me put some labels on my axes. X-label is the way you do this. And in this case I have a very simple label that I want. And the same thing, presumably for Y-label. That will at least put some labels on. Aren't they horribly small? But they are there.
Now, I want to improve this plot in general. Let me point out another thing that I want to do. I don't want to have hold on permanently, so let me put hold off after the second plot. And that's going to avoid difficulties in the future. So I'm just going to save that.
Now in order to improve the size of the labels and so forth that's involved with this, there are a number of things one can do. And in general, I'm going to do this for many of my plots. And so what I want to do is I want to illustrate the fact that my script-- which is called fitting.m, can call another script. And it can call as many scripts as I like.
The script I'm going to call, I have in my editor already. It's called plot defaults. Plot defaults.m. And here are some mysterious calls that you will find out only by reading the help files in general.
By the way, in Octave there's all kinds of help that you can find out by typing things like, help. But in general it's more useful usually to use doc. And so we could do doc, let's say a plat and it would then bring me to a place in the documentation, where the documentation for plot is described. MathLab has got its own help system and you can use that to look up various things. I could do doc of, let's say, set, and it will show me what these set commands that are in this file plot defaults are doing.
The syntax is complicated and it's not worth us dwelling on it at the moment. Let me just explain what it's going to do. First of all it's going to set the default access label font size to be bigger, 20. Second thing it's going to do is it's going to make the width of the lines of the axes two instead of one because the axes on these plots may well be better if they're thicker. In general these plots tend to come up with rather thin lines.
That's useful generally, but the most useful thing to fix these plots, and to get the labelling to be a decent size turns out to be to shrink the size of the plot leave the font size the same. So what this command does is it basically sets the paper units, the paper orientation, and the paper size to be three inches by four inches, height versus width. And then it sets the paper position in such a way that we aren't writing off the paper.
As I said, all of this is subtle and you wouldn't necessarily want to know all the details of this. I'll happily make this file available to you. But all I have to do in order to execute those commands in that file, plot defaults, is write the command plot defaults. And I'm going to do that before my first plot. So plot defaults should read in that file that I was just looking at, this file, and execute the commands in it.
Notice, by the way, comments, very important. Because these commands are mysterious, I put some commentary to remind you what they're supposed to be doing next to them, and the way the comment is defined is by having a percent line at the beginning of the line, or actually anywhere else in the line for that matter. OK.
Let's save this new file and run it again. And lo and behold it's run. Probably-- I may not have several of the defaults right because I've been doing a number of things in this Octave session. If I get tired of this Octave session-- I've run 25 different commands on it, it's telling me-- and I want to start a fresh, it's sometimes helpful to start a new, fresh session.
I can do this very straightforwardly, we're just saying, exit, and then starting over again. That's one way to be sure you've got a nice, fresh session. One of the nicest things about Octave is it actually still remembers what your commands were, even though you've got a new session.
So here's what the plot looks like, in the case when I run it with plot defaults and executed before any of other plotting commands. So the plot defaults needs to happen before anything else. And now what you see is much better, much bigger at any rate labels on the axes, et cetera, et cetera.
Things aren't perfect. There's a little y is crashed with the x there, but anyway. You can tweak around with those to your heart's content. If this were fine, my final plot, what I wanted to save, one of the ways I could save it would be to do some kind of screen capture on this window that I'm plotting it in. That would give me a rather cumbersome and not very pretty plot.
There is another way of plotting, of saving this plot. And that is to use the command print. So print is actually printing out the plotting. One has to tell print what format one wants. Supposing I want EPS format, I could say D EPS. And suppose that I know what file I want to save it into, I could, for example, write fitted.EPS, like that.
So this tells it to print out this plot into an EPS file, which is then named fitted.EPS. Let's see what happens. Nothing obvious, except that if I now look in the directory, which in Octave I can do by typing LS, there is a file called fitted EPS. I don't want to get out of my Octave session. I'm in the same directory here. Here it is, fitted EPS. Let's have a look at that file using ghost view, and there it is.
This is now a good quality file that I might be proud to show to my professor. It's actually not in color. That's because I use EPS. I think it's EPS C for color. Let me try it. Let's run that again and now look at it again, and see, yes, it's color. Now it's color.
So that's how to get a plot and to save it looking halfway decent. And that's where we'll end.
This is one of over 2,400 courses on OCW. Explore materials for this course in the pages linked along the left.
MIT OpenCourseWare is a free & open publication of material from thousands of MIT courses, covering the entire MIT curriculum.
No enrollment or registration. Freely browse and use OCW materials at your own pace. There's no signup, and no start or end dates.
Knowledge is your reward. Use OCW to guide your own life-long learning, or to teach others. We don't offer credit or certification for using OCW.
Made for sharing. Download files for later. Send to friends and colleagues. Modify, remix, and reuse (just remember to cite OCW as the source.)
Learn more at Get Started with MIT OpenCourseWare