Clear Filters
Clear Filters

how can I plot an increase and decrease in tempearture as x-axes (i.e. from 25 to 700, 700 to 500 all on x-axes), agains different y-axes

1 view (last 30 days)
load A
plot(A.T_bred,A.O2);hold on;
plot(A.T_bred,A.CO2);hold off;

Accepted Answer

Star Strider
Star Strider on 13 Jan 2023
Edited: Star Strider on 13 Jan 2023
The tiledlayout function can do this in a relatively straightforward manner.
LD = load(websave('A','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1262340/A.mat'));
A = LD.A
A = 1500×4 table
CO CO2 O2 T_bred __ ______ ______ ______ 0 3.8976 20.96 25 0 3.8316 20.952 25 0 3.8046 20.928 25 0 3.7943 20.919 25 0 3.7947 20.914 25 0 3.7846 20.91 25 0 3.7678 20.906 25 0 3.7533 20.902 25 0 3.7325 20.9 25 0 3.7083 20.899 25 0 3.6821 20.891 25 0 3.6572 20.877 25 0 3.6352 20.854 25 0 3.6148 20.829 25 0 3.5977 20.806 25 0 3.5807 20.783 25
figure
tiledlayout(1,2, 'TileSpacing','none') % Define Layout With No Spaces Between Tiles
nexttile
plot(A.T_bred,A.O2)
xlim([25 700])
nexttile
plot(A.T_bred,A.CO2)
xlim([500 700])
set(gca, 'XDir','reverse') % Reverse X-Axis Direction In Second Tile Plot
I am not certain what you want to do, however this should get you started.
EDIT — (13 Jan 2023 at 16:54)
Sorting ‘T_bred’ and plotting against it —
As = sortrows(A,4) % Sort On 'T_bred'
As = 1500×4 table
CO CO2 O2 T_bred __ ______ ______ ______ 0 3.8976 20.96 25 0 3.8316 20.952 25 0 3.8046 20.928 25 0 3.7943 20.919 25 0 3.7947 20.914 25 0 3.7846 20.91 25 0 3.7678 20.906 25 0 3.7533 20.902 25 0 3.7325 20.9 25 0 3.7083 20.899 25 0 3.6821 20.891 25 0 3.6572 20.877 25 0 3.6352 20.854 25 0 3.6148 20.829 25 0 3.5977 20.806 25 0 3.5807 20.783 25
figure
tiledlayout(1,2, 'TileSpacing','none') % Define Layout With No Spaces Between Tiles
nexttile
plot(As.T_bred,As.O2)
xlim([25 700])
nexttile
plot(As.T_bred,As.CO2)
xlim([500 700])
set(gca, 'XDir','reverse') % Reverse X-Axis Direction In Second Tile Plot
[T_bredU,idx] = unique(A.T_bred, 'sort'); % Unique Sorted Values Of 'T_bred' & Indices Of First Instances
Au = A(idx,:); % Sort On 'idx'
figure
tiledlayout(1,2, 'TileSpacing','none') % Define Layout With No Spaces Between Tiles
nexttile
plot(Au.T_bred,Au.O2)
xlim([25 700])
nexttile
plot(Au.T_bred,Au.CO2)
xlim([500 700])
set(gca, 'XDir','reverse') % Reverse X-Axis Direction In Second Tile Plot
This plots and as fuctions of ‘T_bred’ sorted by ‘T_bred’. My code is otherwise unchanged.
Where do you want to go from here (since I do not understand what you want to do)?
[T_bredMax,maxidx] = max(A.T_bred)
T_bredMax = 648
maxidx = 870
idx1 = 1:maxidx;
idx2 = maxidx:size(A,1);
figure
tiledlayout(1,2, 'TileSpacing','none') % Define Layout With No Spaces Between Tiles
nexttile
plot(A.T_bred(idx1),A.O2(idx1))
hold on
plot(A.T_bred(idx1),A.CO2(idx1))
hold off
xlim([25 650])
ylim([0 45])
nexttile
plot(A.T_bred(idx2),A.O2(idx2))
hold on
plot(A.T_bred(idx2),A.CO2(idx2))
hold off
xlim([500 650])
set(gca, 'XDir','reverse') % Reverse X-Axis Direction In Second Tile Plot
figure
tiledlayout(1,2, 'TileSpacing','none') % Define Layout With No Spaces Between Tiles
nexttile
plot(A.T_bred(idx1),A.O2(idx1))
hold on
plot(A.T_bred(idx1),A.CO2(idx1))
hold off
xlim([25 650])
ylim([0 45])
nexttile
plot(A.T_bred(idx2),A.O2(idx2))
hold on
plot(A.T_bred(idx2),A.CO2(idx2))
xline(500, '-k')
hold off
xlim([500 650])
Axr = gca;
Axr.XDir = 'reverse'; % Reverse X-Axis Direction In Second Tile Plot
Axr.YAxis.Visible = 'off';
Axr.YTick = [];
This looks like it could approach what you want. I cannot turn off the y-axis ticks on the right plot (in the centre here), even thougu that should be possible. I am not certain how to deal with the x-axis tick values or labels, so I left them as they are.
.

More Answers (2)

Kevin Holly
Kevin Holly on 13 Jan 2023
Did you want something like this?
load A
yyaxis left
plot(A.T_bred,A.O2);
yyaxis right
plot(A.T_bred,A.CO2);
  1 Comment
Level 2
Level 2 on 13 Jan 2023
@Kevin Holly,@Star Strider Thank you for your answers. But from the example below, I want the 'T-bred' on the y-axes to replace the 'Row' on the x-axes. x-axes to increase and decrease according to the variable data. i.e. varing x-axes. But the y-xes to remain straight not twisted lines.
load A;
figure;stackedplot(A);

Sign in to comment.


Level 2
Level 2 on 13 Jan 2023
@Star Strider Thank you. I just want to combine this two graphs into one graph, It is the same x-axes of T-bred
load A
figure;plot(A.T_bred(1:872),A.O2(1:872),'DisplayName','O2');hold on;plot(A.T_bred(1:872),A.CO2(1:872),'DisplayName','CO2');hold off;legend
figure;plot(A.T_bred(872:end),A.O2(872:end),'DisplayName','O2');hold on;plot(A.T_bred(872:end),A.CO2(872:end),'DisplayName','CO2');hold off;legend

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!