Topic: Plotting Data
Related Reading: Ch. 5 as well as coverage from
lecture.
For each of the following problems, your goal is to create a script that precisely replicates the figure that we demonstrate. Please make sure to pay attention to issues like axis bounds, labels, titles, legends, and other such aesthetics. You should be submitting four separate fies: arch.m, sunflower.m, population.m, and stock.m.
Please submit your homework files via the Git repository.
Create a script sunflower.m that produces such a figure (note well that displayed axes are intentionally omitted from the figure, and that the image aspect ratio is square).
For your own amusement you might see what kind of patterns you get by slightly modifying the value of , but submit the version with the prescribed value.
Population growth can often be modeled with the following function:
For this problem, we want you to graph the population estimate when compared to the actual data for the U.S. population for the period from 1650 up to 2000. We are providing a text file with the actual raw data (statistics taken from wikipedia). Our file has a simple format, starting as
1650 50400 1670 111900 1690 210400 1700 250900You may download the file population.txt to save in your working directory. It can be loaded from within a MATLAB script with a command such as
pop = load('population.txt');in which case the variable pop will be set to an array with n rows and 2 columns.
Write a script population.m that reproduces the following
figure, with the blue dots being the actual data read from the file
and the red line being the estimating function (you can plot the blue
dots in MATLAB by using a line specification of 'b.').
Many financial web sites will display charts similar to the one shown
below showing the price of the Dow Jones Industrial Average as well as
the overall market volume for each day of the most recent year (figure
courtesy of
Yahoo
Finance).
Yahoo also shares its raw data, not
just for the year but for its full history. For this assignment, we
have downloaded the raw data for the Dow Jones going back to 1928.
Our goal is to use MATLAB to reproduce a similar view of the above
timeframe.
We are providing the raw data in a text file (download here), wih one row for each day
of market activity. It is arranged in columns that designate
Year | Month | Day | Daily Opening Price | Daily High Price | Daily Low Price | Daily Closing Price | Daily Volume |
---|---|---|---|---|---|---|---|
1928 | 10 | 01 | 239.43 | 242.46 | 238.24 | 240.01 | 3500000 |
1928 | 10 | 02 | 240.01 | 241.54 | 235.42 | 238.14 | 3850000 |
... | |||||||
2009 | 01 | 29 | 8373.06 | 8373.06 | 8092.14 | 8149.01 | 5067060000 |
2009 | 01 | 30 | 8149.01 | 8243.95 | 7924.88 | 8000.86 | 5350580000 |
Your goal:
You should create a script stocks.m that generates a figure
mimicking the one shown above, as best possible (I do not expect
you to be able to match all of the aestetics for this one). The following
advice will help you.
For this week, feel free to use advanced knowledge about the data set to mimic the figure. In particular, the entry for 2008-01-30 is on row 19919 of that file.
subplot()
function to create one graph with
two plots. Although they are drawn with
different heights by Yahoo, you may draw them with equal
heights in MATLAB (that is the default for subplots).
The top portion of the figure is a line graph based upon plotting the daily closing prices.
set(gca, 'YTick', 1000 .* [1:20]); set(gca, 'YTickLabel', 1000 .* [1:20]);
set(gca, 'YaxisLocation', 'right');
The bottom figure is a bar graph based upon the daily volume.
Extra credit about stock market graph with high/low error bars. Produce a graph analogous to the one below, based on use of the errorbar command and the daily open/high/low/close values. The errorbar command is capable of producing the vertical boxes denoting the high and low prices for the market that day. The three-argument version of the errorbar command in particular allows you to specify a central x and y coordinate for each box, as well as the height of the box. The stems to the left and right of the boxes denote the open and closing prices, respectively, and will need to be plotted separately. There are multiple ways to achieve this, but I would suggest using the left and right arrow data labels with the regular plot command.
(figure
courtesy of marketwatch.com)