How to get rid of certain xticklabels?
2 ビュー (過去 30 日間)
古いコメントを表示
I have a plot that use log2 for x-axis. Now I want to get rid of xticklabels such as 1.41421, 2.82843, etc., and add 28 to the xticklabels. Namely, I would like to have xticklabels as [1, 2, 4, 8, 16, 28, 32]. Note that the constraint is to use log2 instead of original datapoints for x-axis because I want to somehow show linear speedup. How to do that?
compTime_1by1 = [1088.43, 603.71, 354.15, 236.48, 180.46, 159.06];
compTime_2by1 = [2196.49, 1179.91, 648.38, 413.79, 299.63, 268.45];
compTime_3by1 = [3238.68, 1729.27, 930.70, 590.57, 419.56, 337.15];
speedup_1by1 = compTime_1by1(1) ./ compTime_1by1;
speedup_2by1 = compTime_2by1(1) ./ compTime_2by1;
speedup_3by1 = compTime_3by1(1) ./ compTime_3by1;
numberOfCPUCores = [1, 2, 4, 8, 16, 28];
h1 = plot(log2(numberOfCPUCores), speedup_1by1, '-ob');
set(h1, 'MarkerFaceColor', get(h1,'Color'));
hold on;
h2 = plot(log2(numberOfCPUCores), speedup_2by1, '-or');
set(h2, 'MarkerFaceColor', get(h2,'Color'));
hold on;
h3 = plot(log2(numberOfCPUCores), speedup_3by1, '-ok');
set(h3, 'MarkerFaceColor', get(h3,'Color'));
xt = get(gca, 'XTick');
set(gca, 'XTickLabel', 2.^xt);
set(gca, 'FontSize', 14);
title('Parallel Scalability Test');
legend('Aspect ratio = 1 : 1', 'Aspect ratio = 2 : 1', 'Aspect ratio = 3 : 1', 'Location', 'best');
xlabel('Number of CPU cores');
ylabel('Speed-up');
grid on; grid minor;
0 件のコメント
回答 (2 件)
Star Strider
2021 年 11 月 18 日
‘Namely, I would like to have xticklabels as [1, 2, 4, 8, 16, 28, 32].’
It does exactly that when I plot it using the online Run feature here —
compTime_1by1 = [1088.43, 603.71, 354.15, 236.48, 180.46, 159.06];
compTime_2by1 = [2196.49, 1179.91, 648.38, 413.79, 299.63, 268.45];
compTime_3by1 = [3238.68, 1729.27, 930.70, 590.57, 419.56, 337.15];
speedup_1by1 = compTime_1by1(1) ./ compTime_1by1;
speedup_2by1 = compTime_2by1(1) ./ compTime_2by1;
speedup_3by1 = compTime_3by1(1) ./ compTime_3by1;
numberOfCPUCores = [1, 2, 4, 8, 16, 28];
h1 = plot(log2(numberOfCPUCores), speedup_1by1, '-ob');
set(h1, 'MarkerFaceColor', get(h1,'Color'));
hold on;
h2 = plot(log2(numberOfCPUCores), speedup_2by1, '-or');
set(h2, 'MarkerFaceColor', get(h2,'Color'));
hold on;
h3 = plot(log2(numberOfCPUCores), speedup_3by1, '-ok');
set(h3, 'MarkerFaceColor', get(h3,'Color'));
xt = get(gca, 'XTick');
set(gca, 'XTickLabel', 2.^xt);
set(gca, 'FontSize', 14);
title('Parallel Scalability Test');
legend('Aspect ratio = 1 : 1', 'Aspect ratio = 2 : 1', 'Aspect ratio = 3 : 1', 'Location', 'best');
xlabel('Number of CPU cores');
ylabel('Speed-up');
grid on; grid minor;
Since it is apparenlty not doing that for you, perhaps defining —
set(gca, 'XTick',(1:5), 'XTickLabel',2.^(1:5))
will provide the desired result.
.
0 件のコメント
Matt J
2021 年 11 月 18 日
編集済み: Matt J
2021 年 11 月 19 日
h1 = plot(log2(numberOfCPUCores), speedup_1by1, '-ob');
set(h1, 'MarkerFaceColor', get(h1,'Color'));
hold on;
h2 = plot(log2(numberOfCPUCores), speedup_2by1, '-or');
set(h2, 'MarkerFaceColor', get(h2,'Color'));
h3 = plot(log2(numberOfCPUCores), speedup_3by1, '-ok');
set(h3, 'MarkerFaceColor', get(h3,'Color'));
hold off
xticks(log2(numberOfCPUCores));
xticklabels(numberOfCPUCores);
set(gca, 'FontSize', 14);
title('Parallel Scalability Test');
legend('Aspect ratio = 1 : 1', 'Aspect ratio = 2 : 1', 'Aspect ratio = 3 : 1', 'Location', 'best');
xlabel('Number of CPU cores');
ylabel('Speed-up');
grid on; grid minor;
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!