Clear Filters
Clear Filters

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

22 views (last 30 days)
MUTHULINGAM
MUTHULINGAM on 8 Jul 2024
Edited: Drishti on 20 Sep 2024 at 9:08
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 Comments
Sam Chak
Sam Chak on 8 Jul 2024
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.

Sign in to comment.

Answers (1)

Drishti
Drishti on 16 Sep 2024 at 8:30
Edited: Drishti on 20 Sep 2024 at 9:08
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.

Products

Community Treasure Hunt

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

Start Hunting!