Plotting three related data sets with three axes and one line

10 Ansichten (letzte 30 Tage)
Rhianna Sweeney
Rhianna Sweeney am 3 Jan. 2022
Hi there,
I will try not to be complicated here as I am not hugely confident with matlab and it's been a while..
I am trying to replicate a graph with my own data. In the other graph, they have three axes, two x (top and bottom) and one y (lhs). The top and left data sets correspond to the bottom axes. I cannot work out how to do this. I have tried creating a transparent axis on top of the first one, but this obviously leaves me with two lines in the final graph.
The below graph is the one I am trying to emulate. I have data for all three (Flow, delta P and percent occlusion). This example does have a second line but it is theory and can thereofre be ignored for my case.
Below is all I can get so far (I know it is hideous and the data is off).
I am using the code below:
figure;
% Create the first axes
hax1 = axes();
p_occn = [3.0 9.2 13.7 16.2 22.2 32.8 41.3 49.0 60.6 66.9 75 83.3 89.1 94.1 97.6]; % Percent Occlusion
delta_p = [6.39 13.16 22.40 26.71 36.21 47.97 65.01 62.99 93.17 99.64 112.59 108.56 119.22 116.57 118.61]; % Delta P
hplot1 = line(p_occn, delta_p);
% Create a transparent axes on top of the first one with it's xaxis on top
% and no ytick marks (or labels)
hax2 = axes('Position', get(hax1, 'Position'), ... % Copy position
'XAxisLocation', 'top', ... % Put the x axis on top
'YAxisLocation', 'right', ... % Doesn't really matter
'xlim', [200 6000], ... % Set XLims to fit our data
'Color', 'none', ... % Make it transparent
'YTick', []); % Don't show markers on y axis
% Plot data with a different x-range here
Q = [211.794 507.77 844.504 1494.07 2057.38 2791.96 3171.93 4593.52 4573.73 5065.67 5754.67 5811.02 5853.12 5996.7 5894.83]; % Flow
hplot2 = line(Q, p_occn, 'Color', 'r', 'Parent', hax2);
% Link the y limits and position together
linkprop([hax1, hax2], {'ylim', 'Position'});
title('Graph of Change in Pressure vs Flow Rate of Graft as Occlusion Worsens');
xlabel(hax1, 'Percent Occlusion (%)');
xlabel(hax2, 'Flow (ml/min)');
ylabel(hax1, 'Delta P (mmHg)');
Any help would be great!

Antworten (1)

laurent jalabert
laurent jalabert am 5 Jan. 2022
https://fr.mathworks.com/help/matlab/creating_plots/graph-with-multiple-x-axes-and-y-axes.html

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by