在matlab中在二维图上绘制两个因变量对独立变量?

时间:2017-12-01 12:22:20

标签: matlab

我想绘制两个因变量,电子温度和电子密度与高度的关系,如图中所示。 enter image description here

Temperature = [1215.91011364417 1850.01332752710    396.195674732049    2.33318763425785    367.128785760659    1.12519845278610    1041.54280237670    308.561781429331    1403.27246459229    914.721893718804    1131.60868755734    1.12519845278610    614.410587642758    1.46315184861483    1639.85277962398    1.12519845278610    1298.88722417057    1031.22681754873    1436.00999906341    1668.58036010507]
Density = [24649439880.5505 30331375517.0950    32468687222.5687    24308807814.9539    21341517237.4872    35308667370.9386    40665492231.7457    45722093820.9962    51868188863.5582    47190795319.6345    42040060503.1364    32476984617.6228    40532684718.7974    30900215185.8408    34036581740.8683    26599891957.8216    30350230720.2869    33729881290.5469    38973963811.7042    52412248580.7820]

Height = [137.189200000000  137.125590000000    137.194550000000    137.350140000000    137.236270000000    137.254610000000    137.181080000000    137.180590000000    137.233510000000    137.257010000000    137.651370000000    137.182300000000    137.196620000000    137.224820000000    137.189600000000    137.249430000000    137.219690000000    137.130160000000    137.194210000000    137.246930000000].

所有三个变量都是1x20

任何帮助将不胜感激。 感谢

1 个答案:

答案 0 :(得分:2)

此代码显示包含您提供的数据的图。我创建了两组轴,每组包含一个数据。第二组轴在顶部具有x轴,并且是透明的。

Temperature = [1215.91011364417 1850.01332752710    396.195674732049    2.33318763425785    367.128785760659    1.12519845278610    1041.54280237670    308.561781429331    1403.27246459229    914.721893718804    1131.60868755734    1.12519845278610    614.410587642758    1.46315184861483    1639.85277962398    1.12519845278610    1298.88722417057    1031.22681754873    1436.00999906341    1668.58036010507];
Density = [24649439880.5505 30331375517.0950    32468687222.5687    24308807814.9539    21341517237.4872    35308667370.9386    40665492231.7457    45722093820.9962    51868188863.5582    47190795319.6345    42040060503.1364    32476984617.6228    40532684718.7974    30900215185.8408    34036581740.8683    26599891957.8216    30350230720.2869    33729881290.5469    38973963811.7042    52412248580.7820];
Height = [137.18920  137.12559    137.19455    137.35014    137.23627    137.25461    137.18108    137.18059    137.23351    137.25701    137.65137    137.18230    137.19662    137.22482    137.18960    137.24943    137.21969    137.13016    137.19421    137.24693];

% Reorder data
dat = cat(2,Height', cat(2,Density', Temperature'));
dat = sortrows(dat);

ax = {}; % holds both axes handle

figure
hold all

% first axis, first plot
ax{1} = gca;
plot(dat(:,3),dat(:,1),'ko-')
ax{1}.Box = 'off';
ax{1}.XLabel.String = 'Temperature';
ax{1}.YLabel.String = 'Height';
% second axis, second plot
ax{2} = axes();
plot(dat(:,2),dat(:,1),'k-.')
ax{2}.Color = 'none';
ax{2}.YTick = [];
ax{2}.XAxisLocation = 'top';
ax{2}.XLabel.String = 'Density';
ax{2}.XScale = 'log';

% Overlap both axis
ax{1}.Position = ax{2}.Position;

% Clean it up a little bit
ax{1}.XLim = [ 0 3000];
ax{2}.XLim = [1e10 5.3e10]; % You might want to change units here?