Using label in violin plot using gramm

6 次查看(过去 30 天)
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