Plotting > Basics

The versions of Math Processor prior to v. had very limited plotting capabiliites. There was only one function available by the name of plot. That function did not provided any facilities to work with plots at a lower level.

Math Processor v., however, introduced several new functions, which make it very easy to work with plots at a pretty detailed level. Now it is possible to rotate, scale or combine plots in a very flexible manner. In this tutorial, I will show how to use the new plotting routines.

First thing is to create a plot, which is as easy as calling the createplot() function:

>> p = createplot()

Now we have a "Plot" object named 'p' and we can use this object to display our plot. But we first need to add data to it. Let's add a single plot to this object. Paste this line (without the '>>' signs) into MP and hit enter:

>> x = vectorin(-2*pi, 0.005, 2*pi);

The semicolon at the end of the line tells MP to hide the resulting data. Remove the terminating semicolon (;) to see what values were generated. The vectorin() function has created an array of values between -2*pi and 2*pi using a step value of 0.005. Now let's add a sine curves to our plot 'p':

>> addplot(p, x, sin(x))

That was simple! Now we have a plot object with some plot data added to it. Let's view out plot:

>> showplot(p)

hmmm.. Something is not right. All we see is a tiny tiny plot at the middle of screen. We want to view it closely. Let's zoom in:

>> showplot(p, 40, 40)

Cool! Yep now we can see our sine curve! Let's add more data to the plot:

>> addplot(p, x, cos(x), 90, 2, red)
>> showplot(p, 40, 40)
>> showplot(p, 45, 30, 30)

The last line is rotating the whole plot (and not the individual curves) by 45 degrees. We want to remove the first curve:

>> removeplot(p, 0)
>> showplot(p, 40, 40)

I hope you enjoyed the tutorial. For further details, refer to the documentation on plotting.