最近用matlab繪製折線圖,有一些常用的指令記錄下來。
首先是加速比的程序代碼,具體功能記錄在註釋裏面。
x1 = [8 16 32 64 128 256];
x2 = [32 64 128 256];
y = [1 2 4 8 16 32];
y04 = [1 1.7872 3.3846 6.6000 11.8800 15.0666];
y02 = [1.0000 1.7770 3.4421 6.5401 12.5571 24.7838];
y01 = [1 1.9245 3.4636 5.3699];
y005 = [1 1.9240 3.5124 6.8844]; % 定義的數組
set(gcf,'color','white'); % 設置背景是白色的 原先是灰色的 論文裏面不好看
plot(x1,y,'b-','LineWidth',2) % 繪製曲線 設置線寬是2
hold on
plot(x1,y04,'rs-','LineWidth',2)
hold on
plot(x1,y02,'md-','LineWidth',2)
hold on
plot(x2,y01,'rd--','LineWidth',2)
hold on
plot(x2,y005,'bs--','LineWidth',2)
xlabel('節點數','FontWeight','bold') % 橫座標的文字是 加粗的
ylabel({'加','速','比'},'Rotation',0,'FontWeight','bold') % 對於多個文字組成的一定要加大括號 這個語句實現了文字的翻轉 使得文字朝向變成了正的
%title('程序加速比') % 標題
legend({'理想','0.04','0.02','0.01','0.005'},'FontSize',8,'FontWeight','bold')
% 圖例 多個文字組成的 一定要加大括號 才能使得後面設置的 文字大小 文字加粗效果實現
axis([0 272 0 32]) % 設置座標軸的範圍
set(gca, 'XTick',(0:16:280)) % 設置x座標軸的刻度
set(gca, 'YTick',(0:2:32)) % 設置y座標軸的刻度
set(gca, 'FontSize',8) % 設置座標軸字體是 8
grid on % 顯示網格
具體效果如下:
並行效率的代碼也是類似的:
x1 = [8 16 32 64 128 256];
x2 = [32 64 128 256];
y = [1 2 4 8 16 32];
y04 = [1.000 0.8936 0.8462 0.8250 0.7425 0.4708];
y02 = [1.000 0.8885 0.8605 0.8175 0.7848 0.7744];
y01 = [1 0.9622 0.8659 0.8213];
y005 = [1 0.962 0.8781 0.8605];
set(gcf,'color','white');
%plot(x1,y,'b-','LineWidth',2)
%hold on
plot(x1,y04,'rs-','LineWidth',2)
%legend('x','y')
hold on
plot(x1,y02,'md-','LineWidth',2)
hold on
plot(x2,y01,'rd--','LineWidth',2)
hold on
plot(x2,y005,'bs--','LineWidth',2)
xlabel('進程數(節點數)','FontWeight','bold')
ylabel({'並','行','效','率'},'Rotation',0,'FontWeight','bold')
%title('程序加速比')
legend({'0.04','0.02','0.01','0.005'},'FontSize',8,'FontWeight','bold')
set(gca, 'FontSize',8)
axis([0 272 0.4 1])
set(gca, 'XTick',(0:16:280))
set(gca, 'YTick',(0.4:0.05:1))
grid on
結果如下圖所示: