Using label in violin plot using gramm
4 ビュー (過去 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
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'}
回答 (0 件)
参考
カテゴリ
Help Center および File 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!