PlotWideImage

From University of Washington - Ubicomp Research Page
Revision as of 18:51, 24 October 2006 by Jonathan Lester (talk | contribs)
Jump to navigationJump to search

Overview

If you want to plot a data sequence which is very long (i.e. a couple hours of data) but you want good temporal resolution you're going to end with a very wide image, i.e. a 100 x 10,000 pixel image. This page describes a couple ways you can trick Matlab into generating this type of image for you or generate such an image via image compositing, and introduces a function which can be used to generate plots plotWideImage.


Using Matlab Directly

Typically if you try to get Matlab to generate a really big figure winodw Matlab will limit the size of the window to the size of your native resolution or simply output a smaller version when you export the image. The trick to doing this is to use the set command to set the window's attributes directly.

Windows

    Under windows (this may also work under a graphical Linux session) you can generate a large image by setting the 'Position' and 'PaperPositionMode' attributes. Simply set the position, which is of the form [left, bottom, width, height], to the desired wide resolution. And then tell Matlab to make the output match what's on the screen by setting PaperPositionMode to auto (honor the Position setting) Note, that if you resize the window manually with your mouse it will lose its extra wide attribute because the move operator will try to make it fit inside the boundaries of your monitor. Here's an example of how to produce a 10,000 pixel wide image: <matlab>% Plot some random data: figure(1),clf plot( randn(1, 100000) ) % Tell Matlab to make the output the same size as what's on the screen, and make the image really wide: set( gcf, 'PaperPositionMode', 'auto') set( gcf, 'Position', [680 680 10000 420] ) % To avoid a bunch of white space adjust the axis so it uses up most of the available space set( gca, 'Position', [0.01 0.11 0.98 0.8] ) % Save the image: print( gcf, '-dpng', '-r96', 'wideImage_10kpixel_windows.png' ) </matlab> Which should generate something like this:
    Click to view a larger version where you can see the axis, click download hi-resolution version on the next page



Linux

    With no GUI front end Matlab won't let you set the Position property; but, you can still get a really wide image by using the PaperPosition property. If we set PaperPositionMode to manual Matlab will honor the PaperPosition setting when it creates the output image. Note, even though Matlab won't let us set the Position property it will automatically set the PaperPosition for us which we can use <matlab>% Plot some random data: figure(1),clf plot( randn(1, 100000) ) % Tell Matlab to honor the PaperPosition size. When we try to set the Position it will set PaperPosition for us: set( gcf, 'PaperPositionMode', 'manual') set( gcf, 'Position', [680 680 10000 420] ) % To avoid a bunch of white space adjust the axis so it uses up most of the available space set( gca, 'Position', [0.01 0.11 0.98 0.8] ) % Save the image: print( gcf, '-dpng', '-r96', 'wideImage_10kpixel_linux.png' ) </matlab> Which should generate something like this:
    Click to view a larger version where you can see the axis, click download hi-resolution version on the next page



plotWideImage

plotWideImage is a Matlab function which lets you plot a very long vector of data and produces a very wide image using plotting directly from Matlab.

To generate our final image we need to specify three arguments, a filename, a data vector, and an options struct (which has three required members). Here's a quick example on how to use the function: <matlab>clear options; array = [10+randn( 1, 512*60*60 ); 25+randn( 1, 512*60*60 ); -10+randn( 1, 512*60*60 )]; options.SR = 512; options.pixelsPerSec = 5; options.maxDuration = (length(array)+1024)/options.SR; plotWideImage( 'testImageSeq.png', array, options ); </matlab> Which should produce an image similar to this:

Click to view a larger version where you can see the axis, click download hi-resolution version on the next page


And here's an example of some accelerometer data:

Click to view a larger version where you can see the axis, click download hi-resolution version on the next page



Usage

    <matlab> % plotWideImage( outputFileName, array, options ) % % This function will plot the data in array as a large image sequence. Plots are % generated by plotting portions of the data over several figures and outputting % each figure as an image which is composited together at the end of the process. % % Temporary files are created in the current directory and are deleted when the % compositing process is complete. % % outputFilename should be a single character string of the form 'arrayPlot' the % appropriate extension will be added to the end of the filename % if it doesn't exist % array should be an N x M column array where N is the number of vectors % in the array and M is the length of the data vector. Currently % only fixed sample rate arrays can be passed. Arrays with % timestamps can be converted to fixed sample rate arrays by % using interp1. % options is a struct containing meta data for the plot options. See below % % _______________________ % Required options: % .SR sample rate (in Hz) of the array % .pixelsPerSec determines how wide a seconds worth of data will appear on % the output plot (in pixels/second) % .maxDuration determines the width of the plot by specifying how long the plot % should be. For example, if you have 10 plots and want them all to % be the same width you would simply pass the longest duration % (in seconds). Note that .maxDuration * .pixelsPerSecond approximates % how wide the data portion of the plot will be % % _______________________ % Additional options: % Options with a '*' indicate that they are structs and must contain a number of elements equal % to size(array,1). % % .plotOptions* is a struct containing options to be passed to the plot command for example: % .plotOptions = {}; % .plotOptions{end+1} = ', 'k-', 'LineWidth', 2'; % .plotOptions{end+1} = ', 'b-', 'LineWidth', 1'; % .plotCommand* is a struct containing the name of the matlab operation used to generate the % plotted data, i.e. 'plot', 'stairs', 'stem', etc. % .y_axisMinMax is a 1x2 array containing the user specified min/max values for the y-axis % if no value is specified the function will use the min/max of array % .resolution the dpi of the output image (default is 96dpi -- screen resolution) % .y_axisTickInterval is the interval between y-axis tick marks (in 'array' units), if no % value is specified the range will be divided into approximately 10 ticks % i.e. if your data ranges from -1 to 1 ticks will be placed at: % [-1:0.2:1] % .x_axisTickInterval is the interval between x-axis tick marks, if no value is specified a rate % of 5 seconds will be used. This value should be specified in seconds. % .testImage if 1 creates a test image to make sure the output matches what's expected % default is 0 % .backgroundText is a text string which will be printed in large letters behind the graph % .backgroundTextColor is a 1x3 array that specifies the color of the background text (1=white 0=black) % .legendText is a cell of string containing legend descriptions for the arrays being plotted % .legendPosition string containing an overriding value for the 'location' parameter of the legend % tight axis fitting is not performed if you specify a location, so the % legend will end up slightly away from the axis edges % .axisOff if 1 turns plotting of the axis off (for generating overlays) % .textOff if 1 the stats nomrally printed at the top are removed % .histOff if 1 the histograms normally printed at the top are removed % .histText specify labels for the histograms, for no labels specify blank strings % .histInMiddle place the histogram in the middle of the figure ignoring the text extent % normally used to position the histogram % % % _______________________ % Options.defaults: % is a struct inside options which can be used to override the default parameters used inside % this function (each option is of the form options.defaults.x) % ..figNo the figure number to be used to plot with % ..figVis is the figure window visible during rendering? % ..axisHeight height of the matlab axis object in pixels % ..axisKeepAway_y global option for how many pixels to use as buffer space for things like the % ..axisKeepAway_x axes labels, the default values of 30,60 are used in other scripts so if you % change them here be sure you update them elsewhere % ..histogramBins number of bins to use, default is 20 (or range(vector) if smaller) % ..histogramSz default dimensions of the histograms [width height] % ..histSpacing number of pixels between histograms (default 10) % ..histFontSz size (in points) of the font to use when plotting histograms (default 6) % </matlab>