轴缩放非常小的数字



我有一个代码,我需要在其中绘制两个函数,其中x轴由非常小的数字组成(平均大小为10^-6)。这是代码:

Na = 10^18;
Nd = 10^15;
X_n = 9.941913007683443e-05;
X_p = 9.931981026656786e-08;
eps_0 = 8.85*10^-14;
eps_r = 11.8;
q = 1.6*10^-19;
x1 = -X_p:0.000000001:0;
x2 = 0:0.00000001:X_n;
v1 = (q*Na/eps_0*eps_r).*(x1.^2/2+X_p.*x1)+(X_p^2*q*Na)/(2*eps_0*eps_r);
v2 = (-q*Nd/eps_0*eps_r).*(x2.^2/2-X_n.*x2)+(X_p^2*q*Na)/(2*eps_0*eps_r);
figure (2)
plot(x1,v1,'r');
figure (1)
plot(x2,v2);
% plot(x1,v1,'r');
% hold on;
% plot(x2,v2);

这里,这两个图是分开的,所以你可以看到它们有多大的不同。我想把这两个函数画在一张图上。正如你所看到的,我尝试了按住命令,但由于每个函数的大小不同,它不起作用。我也试过使用axis equal, axis auto等命令,但效果不太好。

我能做什么?

谢谢。

尝试缩放一个或两个,直到它们之间的差异不是那么明显。否则,较小的将总是实际上(和视觉上)为零。

您考虑过使用subplot吗?

如果你必须使用x1x2,我不相信你可以在同一个图中有两个图形。但是你可以试试:

subplot(2,1,1)
plot(x1,v1,'r');
title('title one')
xlabel('some values')
ylabel('some other values')
lg = legend('This curve represents...')
subplot(2,1,2)
plot(x2,v2,'b');
title('title two')
xlabel('some values')
ylabel('some other values')
lg2 = legend('This curve represents...')

编辑

试试这个!我给你一个你可以修改的例子。

x1 = 0:0.1:40;
y1 = 4.*cos(x1)./(x1+2);
x2 = 1:0.2:20;
y2 = x2.^2./x2.^3;

有两个x值和两个y值是不同的,然后使用line:

line(x1,y1,'Color','r') % The first plot!
haxes1 = gca; % handle to axes
set(haxes1,'XColor','r','YColor','r') % sets the first x,y_axis of different color, this time will be red, but you can change this if you want

:

haxes1_pos = get(haxes1,'Position'); % store position of first axes
haxes2 = axes('Position',haxes1_pos,...
          'XAxisLocation','top',...
          'YAxisLocation','right',...
          'Color','none');

完全按照你看到的样子使用代码。如果你愿意,你可以跳过'YAxisLocation','right',...,试试代码,让我知道它是如何运行的。

最新更新