"1D" scatter plot without x-axis

조회 수: 74 (최근 30일)
Daniele Gerosa
Daniele Gerosa 2020년 5월 25일
댓글: Daniele Gerosa 2020년 5월 26일
Hi all,
I would like to plot groups of scattered dots like in the pictures attached below. I specify the y coordinates, while the x coordinates can be arbitrary as long as the grouped structure is highlighted (and they also should be different, at least within the same group of points). The groups should be placed in the same "column" like in the first picture or in "separate columns" like in the second (maybe with some dashed line that vertically separates one "column" from the other). It would be nice to see code for both options.
Thanks.
  댓글 수: 1
Christophe
Christophe 2020년 5월 25일
You can hide XTick by assigning an empty element.
figure;
h = axes;
h.XTick = [];

댓글을 달려면 로그인하십시오.

채택된 답변

Tommy
Tommy 2020년 5월 26일
If you only have one-dimensional data but you want to display it on two axes, you'll have to tell MATLAB where (i.e. if you have the y data, you need to pick corresponding x data). Also, if you want clusters to be scattered in a circular shape, rather than along vertical lines, you could jitter the x data to add some variation along the x axis.
Here is one example which centers each cluster of data at its mean y value:
% random data
data{1} = 16 + randn(10,1);
data{2} = 10 + randn(10,1);
data{3} = 4 + randn(10,1);
c = {'k','r','g'}; % colors
% separated
ax = axes(figure, 'NextPlot', 'add', 'XColor', 'none');
for i = 1:numel(data)
y = data{i};
x = mean(y) + std(y)*randn(numel(y),1); % x data have same mean and standard deviation as y data
scatter(ax, x, y, c{i}, 'MarkerFaceColor', c{i})
end
Here is another example which stacks the clusters. The main difference is that each cluster here will be centered around x = 0, rather than x = mean(y).
% random data
data{1} = 16 + randn(10,1);
data{2} = 10 + randn(10,1);
data{3} = 4 + randn(10,1);
c = {'k','r','g'}; % colors
% stacked
ax = axes(figure, 'NextPlot', 'add', 'XColor', 'none');
for i = 1:numel(data)
y = data{i};
x = std(y)*randn(numel(y),1); % x data have same standard deviation as y data but mean of 0
scatter(ax, x, y, c{i}, 'MarkerFaceColor', c{i})
end
xlim(ax, ax.XLim + [-0.1 0.9]*range(ax.XLim));
Of course, you could determine the x values any way you want. They don't need to be drawn from a normal distribution. Both of these examples would plot two clusters on top of each other if the clusters happen to have a similar mean.
  댓글 수: 1
Daniele Gerosa
Daniele Gerosa 2020년 5월 26일
Hi Tommy, it seems like the code is producing the exact output I had in mind. Thank you very much!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by