GLG410--Computers in Earth and Space Exploration
Graphical Interaction with Plots and Subsetting Quick reminder of Yellowstone
Yellowstone - Teton epicenter
Using paths in Matlab to keep things tidy
ginput, gtext, and find
Today's lecture will continue a discussion of tools for exploring your data.
Set up the example
Let's go back to our Yellowstone seismicity data.
I am going to load the data, set up a few variables, and then plot it:
year = ystone_eqs_sort(:,1);
x_locations = ystone_eqs_sort(:,4);
y_locations = ystone_eqs_sort(:,3);
depth = ystone_eqs_sort(:,5);
magnitudes = ystone_eqs_sort(:,6);
Getting the locations of mouse clicks on a plot
Say you want to have the user select some portion of the data interactively using the mouse. You can get the coordinates of a user's clicks by using the Matlab command . ginput
I added this code to my script so that you can tell the user what to do:
fprintf(1, 'click on lower left and upper right of the area of interest\n')
Note that the \n means "add a new line after this."
NOTE: is a function that is used to write out text (to a file or the command window).
The "1" as the first argument in fprintf tells the function to print the text to the screen.
The script entry looks like this:
[X,Y] = ginput(2);
The argument of 2 to ginput tells it to take two clicks. When you move the mouse over the figure, you will see that the cursor turns into a moving cross hair:
The result in that case is:
click on lower left and upper right of the area of interest
Let's draw a red box then around that selection:
%this draws a box. Realize that it has 5 vertices because you have to close it back around to the beginning
xs = [xmin xmax xmax xmin xmin];
ys = [ymin ymin ymax ymax ymin];
plot(xs, ys, 'r-')
Finding the events within a user-defined box
Now for some real interactivity. Find the events inside that square:
t> tf = x_locations <= xmax & x_locations >= xmin & y_locations <= ymax & y_locations >= ymin;
locs = find(tf);
And, let me teach you about another useful interactive item: Matlab command . This will let us label our box: gtext
NOTE: is a function that lets you write out a message or question to the screen and ask the user for input. The user can then type anything, and that input is then assigned to the variable specified by input input. If you want to get really fancy, tryout the function . This gives you a popup box to write your response.
your_label = input('What is your label for that selection? \n', 's');
gtext(your_label, 'Color', 'r')
I typed swarm as the label at the command line.
Operations on the selection
Histograms of event year
years_for_hist = unique(year(locs));
n = hist(year(locs), years_for_hist);
Here I have introduced the concept of .
By calling subplot subplot we can place multiple axes into the same figure window and specify where in the window we want the axes to be plotted.
Which of the above did you like better? Do you see what was different?
Histograms of event magnitude
GLG410 Computers in Earth and Space Exploration
Last modified: October 4, 2011