plotSeries - Color-code multiple plots

plotSeries allows multiple plots to be easily color-coded
404 Downloads
Updated 17 Oct 2011

View License

[ PH CH colorList ] = plotSeries(AH,x,y,s,colormap,OPTIONS)

Plots x and y data with each column of y color-coded according to scalar values defined in s. plotSeries is particularly useful to illustrate how a x-y dataset *changes* in response to some value, s.

Colormap can be defined by a string or a four-column matrix. When a string is used or the argument is left empty, the colormap spans all values of s, linearly. When a four-column matrix is provided, the first column corresponds to potential values of s, the other three define the corresponding RGB values. The RGB values used for each column of y are interpolated from the rows of colormap, so there is no requirement for the number of rows of colormap to match up w/ the length of s.

If length(s) > 1, then a colorbar will be included as a legend for the line coloring.

Optional lineseries specifications (OPTIONS) will be applied to all plots.

plotSeries outputs a list of plotHandles (PH), a colorbar handle, (CH), and the colorList used for the plot. The colorList output can be used directly as the colormap argument for other calls to plotSeries, providing a mechanism to easily produce multiple plots using similar coloring schemes.

Example (cut and paste into the command-line):

% Show how sinc function changes as a function of s
s = 1:10;
x = (-1:1e-3:1).';
y = sinc(x*s);
figure; plotSeries(x,y,s,'jet','LineWidth',2);
xlabel('x-values');ylabel('y-values');

Inputs:
AH - [1x1] [OPTIONAL] Axes handle
x - [NxS / Nx1] X-coordinate data
y - [NxS] Y-coordinate data
s - [1xS] Scalar value associated with each data series (length(s) = size(y,2))
colormap - [Cx4] Colormap to use for dataset coloring. Can be colormap string OR four-column colormap with 1st column corresponding to potential s values and 3 remaining columns corresponding to color. Note that the colormap will be interpolated to find the appropriate color for each dataset. ([] for 'default' colormap)
OPTIONS - Optional arguments for plot command

Outputs:
PH - [Sx1] Plot handle
CH - [1x1] Colorbar handle
colorScale - [Sx4] colormap w/ 1st column corresponding to s values and 3 remaining columns corresponding to color

N - Number of x-y coordinates to plot for each dataset
S - Number of datasets
C - Number of colors provided in colormap

Cite As

James Hall (2024). plotSeries - Color-code multiple plots (https://www.mathworks.com/matlabcentral/fileexchange/33322-plotseries-color-code-multiple-plots), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2008b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Colormaps in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.0.0