PlotWideImage: Difference between revisions

From University of Washington - Ubicomp Research Page
Jump to navigationJump to search
mNo edit summary
 
mNo edit summary
Line 142: Line 142:
%  ..figVis      is the figure window visible during rendering?
%  ..figVis      is the figure window visible during rendering?
%  ..axisHeight  height of the matlab axis object in pixels  
%  ..axisHeight  height of the matlab axis object in pixels  
%                  (limited by figure's default size in pixels)
%  ..markerColor  [1x3] RGB color for the marker used for image overlapping
%                  (avoid using this color elsewhere in the image or overlapping will fail)
%                Note: Instead of markers used in each image 1 set of marker meta data could
%                      be extracted and the rest of the images assumed to be consistent
%
%
</matlab>
</matlab>
</ul>
</ul>

Revision as of 02:07, 18 October 2006

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. % % % _______________________ % 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 % </matlab>