我有一個log2用于 x 軸的圖。現在我想去掉xticklabels諸如1.41421、2.82843等,并添加28到xticklabels. 也就是說,我想擁有xticklabelsas [1, 2, 4, 8, 16, 28, 32]。請注意,約束是使用log2而不是 x 軸的原始資料點,因為我想以某種方式顯示線性加速。怎么做?
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;
uj5u.com熱心網友回復:
不是針對x的對數繪圖,而是使用semilogx. 這將以對數方式縮放軸,其刻度線將保留實際的x值。然后您可以使用xticks來指定您首選的刻度線位置(例如,以 2 的冪而不是 10 的冪)。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/361459.html
標籤:MATLAB
上一篇:如何正確使用這里的計數功能?
