4

我正在使用八度。我的问题是:我想填充散点图的气泡,并放置一个图例。但是当我尝试使用时出现错误'filled',并且在我使用时没有出现图例legend(...)。我的部分代码如下所示:

%ALL SAMPLES, PHI(Signal) @ THETA(Sample)=0
figure(5)
plot( Angles(:,1)([18:27]),  ALL([18:27]), 10, [1 0 1]);  %Magenta
hold on 
scatter(Angles(:,1)([68:76]), ALL([68:76]), 10, [0 0 0]);   %Black
scatter(Angles(:,1)([86:95]), ALL([86:95]), 10, [1 0 0]);   %Red
scatter(Angles(:,1)([119:127]), ALL([119:127]), 10, [0 1 0]);   %Green
scatter(Angles(:,1)([133:141]), ALL([133:141]), 10, [0 0 1]);   %Blue
hold off
xlabel('Signal PMT angle (Sample angle at 0)'); 
ylabel('Normalized (signal/monitor) intensity');
legend('Control', 'Control', '1+2','Virgin','Cycle #1', 'Location','NorthEast');
title('Plot of All Samples, "-int Intensity"')

我知道它应该是plot( Angles(:,1)([18:27]), ALL([18:27]), 10, [1 0 1], 'filled');,但是当我这样做时我收到错误。此外,传奇似乎永远不会出现。

4

2 回答 2

4

显然在 Octave 中使用legendwith存在问题。scatter基于这篇文章:

http://octave.1599824.n4.nabble.com/Legend-in-scatter-plot-td3568032.html

诀窍是使用该plot函数制作散点图。我编写了以下函数用于在同一轴上绘制一堆散点图。

此函数接收一堆相同长度的元胞数组。元胞数组的每个元素对应一个单独的系列。该函数返回一个长度相同的元胞数组,其中包含与每个图关联的句柄。该函数的参数解释如下:

x_vals:对应于 x 值的双精度数组的元胞数组。

y_vals: 对应于 y 值的双精度数组的元胞数组。

sizes:表示标记大小的双精度元胞数组。

colors:长度为 3 的双精度数组的元胞数组,表示[R, G, B]标记的颜色值。

styles:表示标记形状的字符串元胞数组。

    function [handles] = scatter_series_set(x_vals, y_vals, sizes, colors, styles)

        N = length(x_vals);

        if ( (~ ( N == length(y_vals))) || (~ ( N == length(sizes)))  || ...
             (~ ( N == length(colors))) || (~ ( N == length(styles))) )
            error('scatter_series_set: all arguments must be cell arrays of the same length');
        end

        %plot the first series
        handles = cell([N, 1]);
        handles{1} = plot(x_vals{1}, y_vals{1});
        set(handles{1}, 'linestyle', 'none');
        set(handles{1}, 'marker', styles{1});
        set(handles{1}, 'markersize', sizes{1});
        set(handles{1}, 'color', colors{1});

        %plot additional series if present
        if N > 1
            hold on;
            for ind = 2:N
                handles{ind} = plot(x_vals{ind}, y_vals{ind});
                set(handles{ind}, 'linestyle', 'none');
                set(handles{ind}, 'marker', styles{ind});
                set(handles{ind}, 'markersize', sizes{ind});
                set(handles{ind}, 'color', colors{ind});
            end
            hold off;
        end
    end

下面的例子演示了如何使用这个函数。

x1 = 0:(2*pi/100):(2*pi);
x2 = 2*x1;
y1 = sin(x1);
y2 = cos(x1);
y3 = sin(x2);
y4 = cos(x2);
names = {'a', 'b', 'c', 'd'};

x_vals = {x1, x1, x1, x1};
y_vals = {y1, y2, y3, y4};
sizes  = {10, 10, 10, 10};
colors = {[1, 0, 0], [0, 0, 1], [0, 0, 0], [0.7071, 0, 0.7071]};
styles = {'^', 's', 'x', '+'}

scatter_series_set(x_vals, y_vals, sizes, colors, styles);

legend(names, 'location', 'southeast');

示例代码生成以下图:

示例代码生成的散点图。

于 2013-12-01T04:05:15.880 回答
0

以下对我有用:

n = 100;
x = randn(n, 1);
y = randn(n, 1);
S = rand(n, 1)*20;
hold on
scatter(x(1:50), y(1:50), S(1:50), "red", "filled")
scatter(x(51:100), y(51:100), S(51:100), "green", "filled")
hold off
print('-depsc', 'bubbleplot.eps');

在此处输入图像描述

但是,我无法添加图例,也没有发现任何错误报告或缺少此功能的指示。因此,作为替代方案,我建议在您的情节中添加标记和文本。

于 2011-05-18T11:26:46.533 回答