我正在创建一些数据的散点图,就像你一样,我有一些重复的数据点,我想将它们绘制成具有一些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),然后绘制它以使圆圈最终成为圆形.如果我重新塑造情节,那么它们最终会成为椭圆形.我最终还有数以百万计的物品,这在传说中是一种痛苦.
有没有更简单的方法?