How to skip a part of y axis in plotting ode code?

4 次查看(过去 30 天)
I want to plot the solution for the following ode but one variable is far from other variable solutions. so If I was advised to skip a part of y axis to look presentable. I want to skip from 1.5*10^9 to 1.3*10^10 in the y-axis. Is that possible?
clc;
clear;
% Define initial conditions
S0 = 1; S_R0 = 0; C0 = 0; C_R0 = 0; M10 = 85000; M20 = 15000; T_H10 = 71000; T_H20 = 12000; T_C0 = 56000; T_REG0 = 8000; IL100 = 0.0085; IFNG0 = 0.12; IL20 = 0.0094;
y0 = [S0, S_R0, C0, C_R0, M10, M20, T_H10, T_H20, T_C0, T_REG0, IL100, IFNG0, IL20];
% Define time span
tspan = [0 8000];
% Solve the system using ode23
[t, y] = ode45(@odes, tspan, y0);
% Plot the results
figure
plot(t, y(:,1), t, y(:,2),t, y(:,3),t, y(:,4),t, y(:,5),t, y(:,6),t, y(:,7),t, y(:,8),t, y(:,9),t, y(:,10),'')
legend({'S', 'S_R', 'C', 'C_R', 'M1', 'M2', 'T_{H1}', 'T_H2', 'T_C', 'T_{REG}'});
xlabel('Time(days)')
xlim([0 800])
ylabel('Cell Density(cells/ml)')
%title(['Solution of ODE System'])
grid on
figure
plot(t, y(:,11), t, y(:,12),t, y(:,13))
legend({'IL10', 'IFNG', 'IL2'});
xlabel('Time(days)')
xlim([200 800])
ylabel('Variables')
% title('Solution of ODE System')
grid on
  3 个评论
Sam Chak
Sam Chak 2024-7-8
I suppose there is a continuity from to in the y-axis. Have you tried creating a graph with the y-axis has log scale? In other words, use the semilogy() command to evaluate if the graph is presentable.

请先登录,再进行评论。

回答(1 个)

Drishti
Drishti 2024-9-16
编辑:Drishti 2024-9-20
Hi Muthulingam,
To skip a part of y-axis of the plot, you can refer to the following workarounds:
  1. Separate subplots can be created for the range of 0 to 1.5 × 10^9, as well as for values starting from 1.3 × 10^10 onwards. This approach allows you to visually omit the unnecessary data points. The limits of the subplot can be defined as:
%for subplot 1
ylim([0 1.5e9])
% for subplot 2
% Calculate the upper limit, ensuring it's greater than 1.3e10
upper_limit = max(max(y(:,1:10))) + 1;
if upper_limit <= 1.3e10
% Ensure a valid range
upper_limit = 1.3e10 + 1;
end
% Adjusted upper y-axis limit
ylim([1.3e10 upper_limit]);
2. You can manually set the 'y-ticks' to show values of specific range in the graph making it more presentable.
% Get current axes
ax = gca;
yticks = [0:1e8:1.5e9, 1.3e10:1e9:max(y(:))];
% Define y-ticks
set(ax, 'YTick', yticks);
Furthermore, you can refer to the MATLAB Documentation of the ‘set’ function.
I hope this helps.

类别

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