Using label in violin plot using gramm

6 Ansichten (letzte 30 Tage)
Arka Ghosh
Arka Ghosh am 12 Feb. 2021
Bearbeitet: Arka Ghosh am 24 Feb. 2021
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 Kommentare
Mario Malic
Mario Malic am 12 Feb. 2021
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 am 12 Feb. 2021
Bearbeitet: Arka Ghosh am 12 Feb. 2021
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.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Genomics and Next Generation Sequencing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by