How to fix the 2 x-axis ticks visual bug/issue? It works, however there is a visual bug in the graph everytime I pan, go into 3d, and reset the view.

2 views (last 30 days)
The code below creates two independent x-axis ticks, both from the top and bottom of the graph. I can also pan, zoom in, and out of the graph. However, the problem arises when I reset the graph back to its original state. The plots (the data lines or charts) get stuck or left behind randomly somewhere in the graph, but not far from where they originally were. Another visual issue is that when I go into 3D mode, the plots don't seem to be in the graphing area; they are somewhat 2D (some points, such as pointer or increment marker plots, are in 3D and move along with the graph) as well as the first x and y ticks; consequently, when I reset the graph, everything now turns into chaos (the plot positions are randomly everywhere). How can I fix this?
How it normally looks:
When I pan and reset the graph:
When in 3d:
Video Demonstration: Google Drive (watch)
I am trying to re-create the 1976 International Standard Atmospheric Model, which I am planning to publish sooner for educational purposes.
PS. I plotted those points I mentioned separately in another section because If I place them in the "linetype" function, it will make the line bolder since I am using 10m increments in array that ranges 0-105000m with layers that is altitude based: 0, 11km, 20km, 32km, 47km, 51km, 71, 84.85km, 90km, 105km.
Here is the code for creating the 2 x-axis tick:
t = tiledlayout(1,1);
ax1 = axes(t);
plot(ax1, Temperature, Altitude, '-.r', 'LineWidth', 2);
hold on;
plot(ax1, Pressure, Altitude, 'b--', 'LineWidth', 2);
ax1.XAxisLocation = 'bottom';
ax1.YAxisLocation = 'left';
ax1.YAxis.Visible = 'on';
% First X-axis
ax1.XColor = 'r';
ax1.YColor = 'k';
ax1.Box = 'off';
xlabel('Temperature (K)')
ylabel('Geometric Altitude (km)');
legend('Temperature', 'Pressure', 'Location','northwest', 'fontsize', 12);
enableDefaultInteractivity( ax1 )
% Second X-axis
ax2 = axes(t);
plot(ax2, 0);
ax2.XAxisLocation = 'top';
ax2.YAxisLocation = 'right';
ax2.YAxis.Visible = 'off';
ax2.Color = 'none';
ax2.Box = 'off';
ax2.XColor = 'b';
xlabel('Pressure (kPa)')
enableDefaultInteractivity( ax2 )
% Limit the axis as-together such that they'll be inline with each others values
ax2.XLim = ax1.XLim;
linkprop([ax1 ax2], 'XLim');
hold off;
Here is the code for the individual layer increment plots (those green circles):
altitudes = [11000, 20000, 32000, 47000, 51000, 71000, 84850, 90000, 105000];
temperature_data = {Temperature_Altitude_1(1101), Temperature_Altitude_2(901), Temperature_Altitude_3(1201), Temperature_Altitude_4(1501), Temperature_Altitude_5(401), Temperature_Altitude_6(2001), Temperature_Altitude_7(1386), Temperature_Altitude_8(516), Temperature_Altitude_9(1501)};
% Display a circular shape on a specific point in line
for i = 1:numel(altitudes)
plot(temperature_data{i}, altitudes(i), 'Marker', 'o', 'MarkerSize', 5, 'MarkerEdgeColor', 'red', 'MarkerFaceColor', 'green');
end
% Display text that indicates the altitude per layer increments
alignment = {'right', 'right', 'right', 'left', 'left', 'right', 'right', 'left', 'left'};
labels = {'11km ', '20km ', '32km ', ' 47km', ' 51km', '71km ', '84.85km ', ' 90km', ' 105km'};
for i = 1:numel(altitudes)
h = text(temperature_data{i}, altitudes(i), labels{i}, 'HorizontalAlignment', alignment{i});
set (h(:), 'Clipping', 'on');

Answers (0)

Categories

Find more on Graphics Objects in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!