Processing math: 100%

Lesson goal: Data Science: Visualize your data with a plot

Previous: Confusion with max and min | Home | Next: Dealing with two column data files

Probably one of the most important aspects of data science is in visualizing data. This means: to make a plot (or graph) out of it.

Since charts are made of rows of data, arrays will be a natural way of holding and presenting your data to the chart drawing function. In the simplest case, a chart has two rows, one for the x, or horizontal axis, and one for y, or the vertical axis.

There is one little issue here: the sample.dat file only contains one column of numbers. What do we do about the other column? Make it up! We'll put the actual data on the y-axis, and make up the x-axis to just be the data point's position in the file (1,2,3,...)

To make the plot, we'll use drawchart which works like this:
drawchart(xdata,ydata,type)
Move the mouse over a dotted box for more information.

A chart will always appear at the very bottom of the browser window. You might have to scroll down to see it.

Now you try. Visualize your data in a graph!

Type your code here:

19
 
1
x = {}
2
y = {}
3
4
h = file_open("sample.dat")
5
if h == false then 
6
 print("File can't be used.")
7
 return 
8
end
9
10
i = 1
11
repeat
12
 data = ??
13
 if data ~= false then
14
  x[i] = i
15
  y[i] = ??
16
  i = i + 1
17
 end
18
until data == false
19
drawchart(x,y,"line")

See your results here: