Plotting Two Sets of Data on 2 X Axes and 1 Y Axis

14 次查看(过去 30 天)
Okay, as of now, am having a series of issues:
I am trying to plot two sets of data (1 is in terms of acceleration and the other is in terms of velocity) w/ respect to a single y axis that is in terms of altitude.
1) When I add my axes, they overlap each other. I don't really know how to space out the x axes ticks and labels without having them cutoff from view.
2) I only want to show 1 set of y axis values, but it appears that two values are being plotted. How would I remove one of them?
3) For some reason, when I resize the graph, the two seperate axis plots are not in alignment (they are aligned when the graph is initially created). What can I do to keep the graphs aligned?
Here is my plot, for reference.
Here is my code as well, where vel and acc are two arrays of data that correspond to the x axis values, and altitude is an array that corresponds to the y axes values:
figure(2)
vel = v_entry.*exp(-1/(2*zeta).*exp(-bz));
plot(vel, altitude/1000, 'LineWidth', 4, 'Color', [0.2, 0.6470, 0.810]);
set(gca, "FontName","Comic Sans MS", "FontSize", 16);
ylabel("Altitude (km)"); xlabel('Velocity (m/s)');
yticks(0:5:55); ylim([0 55]); xticks(0:v_entry/6:v_entry); xlim([0 v_entry]);
ax1 = gca;
hold on
ax1_pos = ax1.Position;
ax2 = axes('Position',ax1_pos,...
'XAxisLocation','bottom',...
'Color','none')
hold(ax2,'on')
plot(ax2, acc, altitude./1000,'LineWidth', 4, 'Color', [0.6, 0.4470, 0.7410]);
yticks(0:5:55); ylim([0 55]); xticks(0:450/6:450); xlim([0 450]);
set(gca, "FontName","Comic Sans MS", "FontSize", 16);
title("Altitude vs Hypersonic Re-Entry Velocity");
xlabel("Acceleration Normalized with Gravity (g)");
  9 个评论
VBBV
VBBV 2020-12-18
The dots ... represent your rest of code as before. Not to use as is
VBBV
VBBV 2020-12-18
编辑:VBBV 2020-12-18
vel = v_entry.*exp(-1/(2*zeta).*exp(-bz));
plot(vel, altitude/1000, 'LineWidth', 4, 'Color', [0.2, 0.6470, 0.810]);
set(gca, "FontName","Comic Sans MS", "FontSize", 16);
xticks(linspace(0,v_entry,450)); xlim([0 v_entry]);
ax = gca;
set(ax,'XTick',linspace(0,v_entry,450))
hold on
%ax1_pos = ax1.Position;
%ax2 = axes('Position',ax1_pos,...
% 'XAxisLocation','bottom',...
% 'Color','none')
%hold(ax2,'on')
plot(acc, altitude./1000,'LineWidth', 4, 'Color', [0.6, 0.4470, 0.7410]);
yticks(0:5:55); ylim([0 55]); xticks(linspace(0,450,450)); xlim([0 450]);
set(gca, "FontName","Comic Sans MS", "FontSize", 16);
ax1 = gca
set(ax1,'XTick',linspace(0,450,450))
title("Altitude vs Hypersonic Re-Entry Velocity");
xlabel({'Velocity (m/s)';'Acceleration Normalized with Gravity (g)'});
ylabel("Altitude (km)");

请先登录,再进行评论。

回答(1 个)

Doddy Kastanya
Doddy Kastanya 2020-12-17
To avoid overlap of the two x-axis, you might want to use 'top' for 'XAxisLocation' for ax2.
  1 个评论
Peter Sakkos
Peter Sakkos 2020-12-17
I tried that, and I agree, but I'm still having a sizing issue where the graphs aren't properly aligned.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Axis Labels 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by