Using label in violin plot using gramm

조회 수: 6 (최근 30일)
Arka Ghosh
Arka Ghosh 2021년 2월 12일
편집: Arka Ghosh 2021년 2월 24일
I'm using gramm to draw a violin plot.
a = cell(1, 5);
a(:) = {'exp'};
b = cell(1, 4);
b(:) = {'con'};
data_x = [a b];
data_y = randi([1 10],1, 9);
data_colors = data_x;
obj_plot = gramm('x', data_x(:), 'y', data_y(:), 'color', data_color(:));
% other relevant code %
handle_fig = figure('Position', [0 0 600 300]);
rng('default');
obj_plot.draw();
The above plot would create two violins. I need to add the number of datapoints (5 in this case) on top of the violins.
gramm (documentation) suggests passing the data in the name-value pair 'label', something like the line below
obj_plot = gramm('x', data_x(:), 'y', data_y(:), 'color', data_color(:), 'label', value);
However, I'm not sure what to pass as the value of 'label'.
If I pass,
obj_plot = gramm('x', data_x(:), 'y', data_y(:), 'color', data_color(:), 'label', [5, 5]);
it throws the error - Data inputs have different lengths !
I guess, it is expecting a label for each datapoint in y, but that is not what I'm looking for.
I've also tried using the text() function, but that didn't work either.
a = cell(1, 5);
a(:) = {'exp'};
b = cell(1, 4);
b(:) = {'con'};
data_x = [a b];
data_y = randi([1 10],1, 9);
data_colors = data_x;
obj_plot = gramm('x', data_x(:), 'y', data_y(:), 'color', data_color(:));
% other relevant code %
handle_fig = figure('Position', [0 0 600 300]);
rng('default');
obj_plot.draw();
text([1 2], [5 5], {'5' '5'});
It doesn't throw any error, but it doesn't print any value either.
What am I doing wrong, and how to fix the problem?
  댓글 수: 2
Mario Malic
Mario Malic 2021년 2월 12일
What's showing on xlim in your graph? If it's 1 you won't be able to see the text.
text([1 2], [5 5], ['5' '5']);
If you do text like this, it will show '55' on both points. If you want it to specify text for each point, use cell array for it.
{'5', '5'}
Arka Ghosh
Arka Ghosh 2021년 2월 12일
편집: Arka Ghosh 2021년 2월 12일
Hi Mario,
I tried adding
obj_plot.axe_property('XLim', [0 3]);
but text() didn't work. It didn't print anything.
Thanks for pointing out the problem in this line.
text([1 2], [5 5], ['5' '5']);
I've changed it.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Genomics and Next Generation Sequencing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by