1 | function color_plot(x,colors,varargin)
|
---|
2 | % COLOR_PLOT Scatterplot with colored points.
|
---|
3 | % color_plot(x) makes a scatterplot of x(:,1) versus x(:,2) with points colored
|
---|
4 | % according to quantiles of x(:,3).
|
---|
5 | % color_plot(x,n) specifies the number of color quantiles (default 4).
|
---|
6 | % color_plot(x,colors) specifies an RGB matrix of colors (the number of rows
|
---|
7 | % determines the number of quantiles). The default is YlGnBu_colors.
|
---|
8 | % color_plot(...,'ColorBar',1) adds a color bar with tick marks from the
|
---|
9 | % quantile values.
|
---|
10 | %
|
---|
11 | % Example:
|
---|
12 | % xy = ndgridmat(linspace(-12,12,20),linspace(-12,12,20));
|
---|
13 | % z = sin(sqrt(xy(:,1).^2 + xy(:,2).^2));
|
---|
14 | % color_plot([xy z]);
|
---|
15 | %
|
---|
16 | % See also YlGnBu_colors.
|
---|
17 |
|
---|
18 | % Written by Tom Minka and Charles Sutton
|
---|
19 |
|
---|
20 | args = makestruct(varargin);
|
---|
21 | default_args = struct('ColorBar',0);
|
---|
22 | args = setfields(default_args,args);
|
---|
23 |
|
---|
24 | if nargin < 2
|
---|
25 | colors = 4;
|
---|
26 | end
|
---|
27 | if length(colors) == 1
|
---|
28 | nlevels = colors;
|
---|
29 | colors = YlGnBu_colors(nlevels);
|
---|
30 | else
|
---|
31 | nlevels = rows(colors);
|
---|
32 | end
|
---|
33 | % color groups
|
---|
34 | [c,q] = cut_quantile(x(:,3),nlevels);
|
---|
35 | for lev = 1:nlevels
|
---|
36 | i = find(c == lev);
|
---|
37 | plot(x(i,1),x(i,2),'o','Color',colors(lev,:),'MarkerFaceColor',colors(lev,:));
|
---|
38 | hold on
|
---|
39 | end
|
---|
40 | hold off
|
---|
41 |
|
---|
42 | colormap(colors);
|
---|
43 |
|
---|
44 | if args.ColorBar
|
---|
45 | caxis ([0,1]);
|
---|
46 |
|
---|
47 | cTickLbls = cell(numel(q), 1);
|
---|
48 | for i = 1:length(q)
|
---|
49 | cTickLbls{i} = num2str(q(i), '%11.2g');
|
---|
50 | end
|
---|
51 |
|
---|
52 | colorbar('YTick', linspace(0,1,nlevels+1), 'YTickLabel', cTickLbls);
|
---|
53 | end
|
---|
54 |
|
---|
55 | set(gca,'Color','none')
|
---|