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
ifh == falsethen
6
print("File can't be used.")
7
return
8
end
9
10
i = 1
11
repeat
12
data = ??
13
ifdata ~= falsethen
14
x[i] = i
15
y[i] = ??
16
i = i + 1
17
end
18
untildata == false
19
drawchart(x,y,"line")
See your results here:
What will you fill in for the data = line, which is to read in the next number from the data file? And, if data is read in OK (in the if block), what will you set y[i] equal to (this will be what goes on the y, or vertical axis of your plot)?
Share your code
Show a friend, family member, or teacher what you've done!