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

17 vues (au cours des 30 derniers jours)
Peter Sakkos
Peter Sakkos le 17 Déc 2020
Modifié(e) : VBBV le 18 Déc 2020
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 commentaires
VBBV
VBBV le 18 Déc 2020
The dots ... represent your rest of code as before. Not to use as is
VBBV
VBBV le 18 Déc 2020
Modifié(e) : VBBV le 18 Déc 2020
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)");

Connectez-vous pour commenter.

Réponses (1)

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

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by