PG: This follows from the (much earlier) collect-datapoints project. The next page (improving your graphing app) gives a complex visualization that requires some data processing.
MF: SCRAP. I feel similarly (as with the previous page) here. If a person really wants to do data visualisation, building tools from Scratc (er, Snap) is "the hard way" to explore the data. Why build a tool that already exists? Just to show that you can? It's too much and distracting from the goal of exploring the power of data.
Plotting a single point, given its two coordinates, should feel this basic:
Then you could graph a list of data points by inventing a block like just like your work in Unit 2 Lab 2. Depending on the kind of graph you want, you can connect the dots or not.
That seems like all you should need. But what if the scale of your data does not fit on the Snap! stage (between -240 and 240 in the x direction and between -180 and 180 in the y direction)? For example, what if you want to plot the popularity of a baby name over time, like this?
The years can't be plotted on the horizontal because those values are completely off Snap!'s stage. And the percent values 0, 0.1, 0.2, 0.3, etc., are so close to each other that they would all look the same. We wouldn't see the increase in popularity between 1960 and 1980 at all. We need a way to convert between Snap! stage coordinates and the values—we'll call them the graph coordinates—for a given set of data points.
set graph scale
block with the inputs it already has (-2, 4, 30, 300) to see what it does. In addition to drawing on the screen, it sets several variables that your other blocks will need so that they know the intended screen dimensions. set graph scale
to see where it puts the axes and how it represents the substitutes for the axes, when the point (0, 0) would not appear on the stage. Drag the sprite a few places to see if the sprite says what you expect. Then change the inputs of set graph scale
to fit the range of years and percents in name data and click it to reset the scale of the screen. Again, check to see if your sprite says what you expect when you move it around the stage. On the baby name graph for Derek, the point (1971, 0.25) is roughly in the middle of the screen. Check to see if is working as you expect it to.
DerekData1927to2015
. The points of your graph may or may not be connected and the axes won't have labels, but it should otherwise look like the graph above.