Basic Example
Table of Contents

Plotting a Function

This first tutorial is intended to be an introduction to SwiftVis and how to use it. This will run through examples that are related to using SwiftVis as a general plotting and analysis tool and not how it relates specifically to Swift data files. We begin with plotting a function. This first example doesn't even require us to read in a file and is about the simplest thing that we can do in SwiftVis.

Most of the time when you are using SwiftVis you start off with a Source and this example is no different. In this case we will begin with a Sequence Source. To add this into the SwiftVis data flow graph you can go to the Insert menu and select Source. Scroll down to Sequence Source or begin typing in the name. Then select OK or press Enter. (Note that there is also a right click context menu on the graph and there are keystrokes for the various menu options.) This will add a box in the graph display that says "Sequence". If you click on that box it will put you into the following state.


The panel on the right shows the properties of the sequence source because it is selected on the left. The sequence source has simple options. It produces the specified number of values between the starting and ending values. By default it produces 10 values between 0 and 1. To see what it outputs you can select the "Output" tab. All graph elements in SwiftVis that have output have an output tab. The following screen shot should you the default output of the sequence source.


For a smooth plot we probably want to evaluate the function at more than 10 points. Change the start value to -5, the end value to 5, and the number of values to 1000. Once you have done this, look at the output tab again and see what has changed. One other quick thing to notice about the output table is the header on the single column of data. It says "v[0]=Sequence". We will see later that the v[0] part is quite significant.

Because this is out simple first example, we will have the data from the sequence source go straight to a plot. So while the sequence source is selected, choose Insert > Plot in the menus. This will bring up a box to the right of the sequence source that has the text "General Plot" on it. You should select the plot then click the button labeled "Add Plot". This will leave you in the following state.


Select "Scatter Plot - Default" from the list and you will get a set of options for the scatter plot. We first want to change the "Secondary Formula" from "1" to "v[0]*v[0]". Note that v[0] here represents the values that are coming from our sequence source. If you ever forget what information is coming from a source or filter, you can look at the output tab on that source or filter and see the values and parameters. As you might guess, what we have basically set this to do is plot $y=x^2$. The horizontal axis has the values coming from the sequence while the vertical axis has those values squared. For more information on how data is passed through SwiftVis and what you can enter into formulas see Elements and Formulas. At this point, your screen should look like the following.


To see the plot all you have to do is click the "Show/Redraw" button at the top of the right panel. This will bring up a window like the following.


This might look like it is drawing a parabola with a thick line, but that isn't actually the case. If you look at the other properties of the scatter plot you will see that currently we have told it to draw the values as circles 10 pixels across and not connect things with lines. What you are seeing is actually 1000 circles drawn right on top of one another. If we want to see just a line, we should change two options. First, change the "Symbol Shape" option from "Circle" to "No Symbol". Second, click on the "Connect with lines?" checkbox so that that option is selected. This will automatically change your plot so that it looks like the following.


One last thing to do to make it clear how this works is to change the secondary formula. Instead of "v[0]*v[0]" we can change it to "sin(v[0])". After doing this click the "Apply Changes" button at the bottom of the right panel and you will see that the plot changes to the following.
