我創建了一些數據的散點圖,與您一樣,並且我有一些重複的數據點,我想用一些alpha值將其繪製爲圓形,以便打樁在同一地點加分是顯而易見的。在MATLAB中繪製帶有alpha值的圓圈
至於我可以告訴你不能設置你plot(x, y, 'o')
產生的小圓圈的alpha屬性,所以我採取使用patch()
吸引了成千上萬的小圓圈的自己:
x = repmat([1:10], [1 10]);
y = round(10*rand(100, 1))/10;
xlim([0 11])
ylim([0 1])
p = ag_plot_little_circles(x', y, 10, [1 0 .4], 0.2);
function p = ag_plot_little_circles(x, y, circle, col, alpha)
%AG_PLOT_LITTLE_CIRCLES Plot circular circles of relative size circle
% Returns handles to all patches plotted
% aspect is width/height
fPos = get(gcf, 'Position');
% need width, height in data values
xl = xlim();
yl = ylim();
w = circle*(xl(2)-xl(1))/fPos(3);
h = circle*(yl(2)-yl(1))/fPos(4);
theta = 0:pi/5:2*pi;
mx = w*sin(theta);
my = h*cos(theta);
num = 0;
for k = 1:max(size(x))
for f = 1:size(y,2)
num = num+1;
p(num) = patch(x(k)+mx, y(k,f)+my, col, 'FaceColor', col, 'FaceAlpha', alpha, 'EdgeColor', 'none');
end
end
end
正如你可以看到,這並不是最優的,因爲我需要知道並設置圖的大小(xlim
和ylim
),然後再繪製它以便圓圈最終呈圓形。如果我重塑劇情,那麼他們最終會成爲橢圓形。我也結束了數以百萬計的物體,這是傳說中的一種痛苦。
有沒有更簡單的方法?
您可以加入一個例子調用你的函數?沒有必要詳細閱讀以弄清楚語法會更容易... – abcd 2011-05-05 06:34:59
是的,好主意。 – Alex 2011-05-05 08:42:47
隨着新的matlab發佈,它似乎是可能的,但它仍然是無證的。見[這裏](http://undocumentedmatlab.com/blog/plot-markers-transparency-and-color-gradient) – WYSIWYG 2015-07-01 09:57:13