在 MATLAB 中使用 set(gca,'LineWidth', x) 创建一个新图形,而原始图像具有默认宽度
Using set(gca,'LineWidth', x) in MATLAB creates a new figure while original image have default width
我在我的图形代码中使用 set(gca,'LineWidth',2)
并获取了两张图片。原始图像是相同的,但第二个只有一个宽度为 2 的轴。我的代码如下
clc; clear all ;
set(gca,'LineWidth',2)
figure('DefaultAxesFontSize',30);
set(0,'DefaultAxesFontName',' Times ');
hold on
x1 =10:10:3000;
% % ---------- reading data -------%
arrival_rate = xlsread('scep.xlsx', 'comparing_thoughput_for123', 'A3:A10');
one_stream = xlsread('scep.xlsx', 'comparing_thoughput_for123', 'B3:B10');
two_stream = xlsread('scep.xlsx', 'comparing_thoughput_for123', 'C3:C10');
x2 = interp1(arrival_rate,one_stream,x1,'pchip') ;
x3 = interp1(arrival_rate,two_stream,x1,'pchip') ;
% plotting throughput
% ------scep qos1 one_stream ------
plota = plot(x1,x2,'r-','DisplayName', ' Single Stream ', 'LineWidth',1);
plot(arrival_rate,one_stream,'ro', 'HandleVisibility','off','LineWidth',2);
% ------scep qos1 two_stream ------
plot(x1,x3,'b-','DisplayName', ' Two Streams ', 'LineWidth',1);
plot(arrival_rate,two_stream,'bs', 'HandleVisibility','off','LineWidth',2);
xlabel('\lambda (events/second)')
ylabel('Thoughput (events/second)')
legend('Location','northwest')
legend show
% title('Effect of arrival rate on average CEP throughput')
% set(gcf, 'LineLineWidth', 2);
set(gcf, 'PaperUnits', 'normalized');
set(gcf, 'PaperPosition', [0 0 1 1]);
set(gcf,'PaperOrientation','l');
print -dpdf graphs/comparing_thoughput ;
我做错了什么?
先创建你的图形,然后在其中设置属性:
figure;
set(gca, 'FontSize',30, 'FontName','Times')
set(gca, 'LineWidth',2)
请注意,如果没有数字,gcf
和 gca
会创建一个,这样他们就可以 return 一个有效的句柄。因此,在您的代码中,您的第一个 set(gca,...)
创建了一个带有轴的图形,然后您调用了 figure
,它创建了另一个图形。
我在我的图形代码中使用 set(gca,'LineWidth',2)
并获取了两张图片。原始图像是相同的,但第二个只有一个宽度为 2 的轴。我的代码如下
clc; clear all ;
set(gca,'LineWidth',2)
figure('DefaultAxesFontSize',30);
set(0,'DefaultAxesFontName',' Times ');
hold on
x1 =10:10:3000;
% % ---------- reading data -------%
arrival_rate = xlsread('scep.xlsx', 'comparing_thoughput_for123', 'A3:A10');
one_stream = xlsread('scep.xlsx', 'comparing_thoughput_for123', 'B3:B10');
two_stream = xlsread('scep.xlsx', 'comparing_thoughput_for123', 'C3:C10');
x2 = interp1(arrival_rate,one_stream,x1,'pchip') ;
x3 = interp1(arrival_rate,two_stream,x1,'pchip') ;
% plotting throughput
% ------scep qos1 one_stream ------
plota = plot(x1,x2,'r-','DisplayName', ' Single Stream ', 'LineWidth',1);
plot(arrival_rate,one_stream,'ro', 'HandleVisibility','off','LineWidth',2);
% ------scep qos1 two_stream ------
plot(x1,x3,'b-','DisplayName', ' Two Streams ', 'LineWidth',1);
plot(arrival_rate,two_stream,'bs', 'HandleVisibility','off','LineWidth',2);
xlabel('\lambda (events/second)')
ylabel('Thoughput (events/second)')
legend('Location','northwest')
legend show
% title('Effect of arrival rate on average CEP throughput')
% set(gcf, 'LineLineWidth', 2);
set(gcf, 'PaperUnits', 'normalized');
set(gcf, 'PaperPosition', [0 0 1 1]);
set(gcf,'PaperOrientation','l');
print -dpdf graphs/comparing_thoughput ;
我做错了什么?
先创建你的图形,然后在其中设置属性:
figure;
set(gca, 'FontSize',30, 'FontName','Times')
set(gca, 'LineWidth',2)
请注意,如果没有数字,gcf
和 gca
会创建一个,这样他们就可以 return 一个有效的句柄。因此,在您的代码中,您的第一个 set(gca,...)
创建了一个带有轴的图形,然后您调用了 figure
,它创建了另一个图形。