2011-04-03 17 views
3

我正在使用八度,它免費的僞MATLAB。 我的問題是這樣的:我想填充我的散點圖的氣泡,以及放置一個圖例。但是,當我嘗試使用「填充」時出現錯誤,並且在使用圖例(...)時沒有傳說。我的代碼 部分看起來是這樣的:Octave(MATLAB),scatterplot圖例和填充不工作

%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');,但是當我這樣做,我收到錯誤。另外,一個傳奇似乎永遠不會出現。

預先感謝您。

回答

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'); 

enter image description here

不過,我不能添加一個傳奇,我沒有找到一個缺失的功能對任何錯誤報告或指示這個。所以,作爲替代方案,我會建議在您的情節中添加標記和文字。

3

顯然,在Octave中使用legendscatter時出現問題。在此基礎上一篇:

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'); 

示例代碼產生以下情節:

Scatter plot generated by the example code.