Plotting Data From A Text File

Reading a Text File

You can use SwiftVis for doing analysis of or plotting up standard text files. The General Data source has a lot of flexibility in what it reads, but the simplest usage is to just read a basic text file. Starting with a new SwiftVis graph, select Insert > Data Source and pick General Data.


If you click on the General Data box that appears you should see the following.


For our purposes, we will only use the simple text option. Click the "Select File" button and navigate to the text file that you want to read. We will be using a text file full of random number available here. Once you've selected the file, click the "Open" button. Now you have indicated which file the source should read from. However, because text files may be changed between reads and while SwiftVis is running, SwiftVis does not automatically read the file. In order to make SwiftVis read the data in the selected file, click the "Read File" button.


Once you have clicked the "Read File" button, verify that the data has been read by selected the "Output" tab at the top of the source's information pane. It should appear somewhat like the following image.


We have now successfully read the data from a file. Keep in mind that if you are reading a large data file, this process may take several seconds. Note the titles of the columns of your data - these will be important during plotting because they reflect how you can access the data once it is passed into a filter, or, in this case, a plot. In the sample data file, we only have two columns of data, which SwiftVis labels as v[0] and v[1].

Plotting Data

In order to plot the data read from the file, we first have to create a plot to use with it. So, right-click on the "General Data" box in the main window and select Insert > Plot to create a General Plot.


Then, select the new General Plot and click the "Add Plot" button. By default, a single scatter plot is created. Select the scatter plot to view its properties.


You can see here that the plot refers to v[0] and v[1] already - setting v[0] as the independent axis and v[1] as the dependent axis. We can look at this plot by clicking the 'Show / Redraw" button along the top - this will show or redraw the currently selected plot. We can see from this plot that the values in v[0] range from 0 to 1 and the values in v[1] range, randomly, from 0 to 5. Similarly, we can see that the graph has plotted the random points held in the data file, using v[0] as the x-axis and v[1] as the y-axis.


If you would like the points connected, simply check the "Connect with lines?" option at the bottom of the pane - the changes will instantly show up on the plot.


As with all other fields in SwiftVis, the plotting fields that currently contain v[0] and v[1] may be changed to reflect other values or augmented by mathematical expressions. For example, if we change the independent axis to be "5*v[0]", then click the "Apply Changes" button at the bottom, we see the following results. Note the unit change on the x-axis.


Hopefully, this tutorial has shed some light on basic SwiftVis usage for plotting data stored in a text file.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License