0:00

So for most data visualization tasks,

Â we're just going to need two-dimensional computer graphics to plot and display the data.

Â In order to do that, we'll need to use different coordinate systems.

Â We use a different coordinate system to plot the data than we use to display the data.

Â We're going to use two-dimensional graphics a lot when we visualize data.

Â We're used to using two-dimensional graphics, for example,

Â for plotting functions and so we'll focus on

Â two-dimensional graphics now as we look at methods for using graphics for visualization.

Â What we're going to learn is the difference between vector graphics,

Â which are used to specify two-dimensional graphics and raster graphics,

Â which are used to display two-dimensional graphics.

Â And then we'll look at the coordinate system specifically that are used for each of them.

Â Vector graphics are the graphics that are used for drawing.

Â We're used to drawing; we take a pen and we'll put our pen down at

Â one point and then we'll move our pen across

Â the paper and then lift our pen up at another point and you get

Â a nice straight line between them - a nice continuous line.

Â In raster graphics, this is the graphics that are used,

Â for example, for our televisions and our phones;

Â they are a rectilinear array of pixels and these pixels are assigned colors.

Â And by assigning certain pixels certain colors,

Â you can represent those same shapes.

Â So you will draw a shape using vector graphics;

Â you will describe a point where you want to

Â start a line and a point where you want to stop

Â a line and you'll - you'll get

Â either a straight line or a smooth curved line between them.

Â And those will be converted to raster graphics for display,

Â which will consist of the pixels that get illuminated along

Â that path in order to display that path that you described with vector graphics.

Â So this process is called rasterization.

Â And so we'll specify a primitive - as

Â in a vector graphics format - we'll describe vertices,

Â points on the plane.

Â And then we will connect those points with strokes - in this case, with straight lines,

Â but they could be curved paths - and then those strokes can - can enclose a region.

Â And so we can fill that region - and we may assign a color for that region.

Â And for strokes who may assign a color and a width of

Â the stroke or have the stroke stylized,

Â say with dashed lines or so on.

Â The process of rasterization starts with these primitives defined by

Â these few data points and converts

Â them into an array of pixels so that they can be displayed.

Â And so this raster format representation of this triangle is as an array of pixels.

Â And the dashed lines represent the original primitive on the left,

Â superimposed over the array of pixels that are - that are representing it.

Â And in this case, we have pixels along the edges that are

Â colored blue and pixels in the filled-in region that are colored pink.

Â And you notice when we rasterize a shape,

Â we can get aliasing.

Â And that's the fact that this nice straight line

Â here in our - in our vector graphics representation,

Â appears as a staircased line.

Â You get the stairstep artifacts when you rasterize a smooth, straight line.

Â And because those stairsteps try to look like the original line,

Â but look a little bit different,

Â we call that an alias;

Â and that problem is called aliasing.

Â When we draw primitives in two dimensions - when we want

Â to draw shapes for two-dimensional graphics - for example,

Â for plotting functions - we're going to need a coordinate system

Â in which to draw those shapes so we know where to place the vertices,

Â for example, of a triangle.

Â And so we need to define a coordinate system.

Â And these coordinates I will call canvas coordinates;

Â they're the coordinates that we're going to draw things with.

Â In this case, the canvas coordinates have been defined to go from minus 1, minus 1

Â to 1, 1 and so they set up this square region of - of a plane.

Â The origin would be here in the middle.

Â You can define your canvas coordinates to be anything you like.

Â You want to define them to be something convenient so that you can

Â draw your shapes without a lot of trouble.

Â In this case, I've drawn a plot of a parabola - the parabola y equals x squared.

Â And so I've got a curved path starting at this point here going to this point here

Â and I've defined my canvas coordinate system to be something convenient for that plot.

Â In this case, I've started it going from minus one-eighth,

Â minus one-eighth to one-and-one eighth, one-and-one-eighth.

Â And that's so that as I move one-eighth,

Â one-eighth in, I'm at the point 0, 0

Â in my coordinate system and I can draw my plot going from 0, 0 to 1, 1 here.

Â And then I've got an additional eighth of a unit

Â surrounding the plot in order to do things - to add meta data,

Â like the title of the visualisation and draw the axes and label the axes.

Â So that's convenient, but as I'm resizing the display,

Â I may want the fonts to be larger or

Â smaller and I'll need a bigger margin surrounding the plot.

Â Or I may want the plot to be larger and the margin to be smaller.

Â So in - in two-dimensional computer graphics,

Â we can set up hierarchical coordinate systems.

Â And this just means you have a canvas in a canvas.

Â In this case, we have a yellow canvas that is the coordinate system for

Â the entire plot - the entire

Â visualization - and then we have

Â an inner canvas that is a coordinate system just for the plotted data;

Â in this case, the parabola.

Â And so I've set up the outer coordinate system to go from 0, 0 to 1,

Â 1 in this region and then I've set up an inner coordinate system to go

Â from one-tenth to nine-tenths and one-tenth,

Â one-tenth to nine-tenths, nine-tenths

Â here and I've defined its coordinate system to go from 0, 0 to 1, 1.

Â So now I can plot inside

Â this coordinate system using coordinates that are convenient for plotting

Â this parabola and then I can plot in

Â this outer coordinate system using coordinates convenient for drawing the decorations,

Â the axes and the title.

Â And so we can define whatever coordinate system we want,

Â wherever we want, in order to make it more convenient to draw two-dimensional graphics.

Â There's also screen coordinates.

Â And these are the coordinates that are used for raster graphics,

Â for the display of the information.

Â And in this coordinate system,

Â we have a grid going from 0, 0 to whatever our screen resolution is.

Â In this case, since we're going from 0, 0,

Â we go to our horizontal resolution minus 1, vertical resolution minus 1.

Â If our screen resolution was 100, 100,

Â we would be going from 0, 0 to 99, 99.

Â And the pixels are located on these grid intersections.

Â And so you have a - a integer coordinate for each pixel location,

Â which is useful when you're actually displaying an image using these pixels;

Â you want to be able to locate each one of these pixels.

Â And so there is a canvas-to-screen transformation that happens.

Â So we're going to define our coordinate system going from some left

Â bottom point to some right top point

Â and and - and then we're going to plot using those coordinates.

Â And those coordinates are going to be converted to

Â the corresponding pixel locations on our display screen.

Â And those pixel locations are going to be defined

Â someplace on the display screen starting at x,

Â y and going to the point x plus the width

Â in pixels minus 1 and then y plus the height in pixels minus 1.

Â So this coordinate system happens automatically and you can define these coordinates to

Â be anything and you can define these coordinates to be any location on the screen.

Â And so your 2D graphics that you're plotting on

Â your canvas can be automatically resized and

Â repositioned anywhere on the screen just by

Â controlling this canvas-to-screen transformation.

Â You can also work directly in screen coordinates by setting up

Â a canvas-to-screen transformation that uses

Â canvas coordinates that match up with your screen coordinates.

Â In this case, you're just setting your left edge and your bottom edge to x and y

Â and you're right edge and your top edge to x and y

Â plus the width minus 1 and the height minus 1.

Â And in this case, you can specify the coordinates of your primitives in

Â vector graphics using the same coordinates

Â for the pixels that - that they will be translated to.

Â I don't recommend doing this because when you're working in screen coordinates,

Â you're not going to know what your output screen display device might be.

Â It could be a cell phone,

Â it could be a television, it could be a watch,

Â it could be a video wall - and all of those will have different resolutions

Â and you want to make sure that your two-dimensional graphics is properly displayed;

Â it's not too small or too large when it's displayed on different devices.

Â So it's better to work in some canvas coordinates that's convenient for you and let

Â the canvas-to-screen transformation worry

Â about converting it to the corresponding pixels.

Â So what have we learned?

Â We've learned that vector graphics is used to describe shapes and that

Â raster graphics are what we use to display those shapes using a table of pixels.

Â And that we can set up coordinates that - that are convenient for us to plot in a canvas

Â and those coordinates are different from

Â the raster coordinates that we use to display the canvas.

Â And we can set up canvases within a canvas,

Â which allows us to divide up the screen in ways that make it more convenient

Â for us to set up a two-dimensional visualization display.

Â So we learned that we describe shapes using vector graphics,

Â but we display shapes using raster graphics.

Â We can describe our shapes using the coordinate system of raster graphics,

Â the coordinate systems of the screens pixels,

Â or we can describe them using the canvas coordinates of our vector graphics,

Â or we - we can use whatever coordinate system is most convenient for us to plot the data.

Â