Create an xy plot with two y-axes

I have the following code. I am trying to create an xy plot with two y-axes. However, I get only one line down. I want y to be the vertical axis to the right and vel to be the vertical axis to the left. I have several datasets for different positions, and I'm trying to place the first one at 0.66 on the x axis, the second one at 1, etc., but I can't get it to work. Help me please.

Regards, Jer

clc
    clear


%Retrieve data and figure setup
filename = 'G:\Protable Hard Drive\PHD Hard Drive\Experimental Data\Bulkrename Trial\Common data for line graphs\Data for line graphs.xls';
a = xlsread(filename, 'Veldef');
vel = 0:1/37:1;
y = -16/15:1/15:21/15;

%X/D=0.66 TSR5
x = 0.66;
exp = a(1:38,2);
ko = a(1:38,4);
rst = a(1:38,6);

%Plot
h = plot(x,exp,x,ko,x,rst);
0
source share
2 answers

One parameter plotyy()

x = 1:10;
y = rand(1,10);
plotyy(x, x, x, y)

A more flexible option is to superimpose two (or more) axes and determine which data you want to display on each of them.

% Sample data
x = 1:10;
y = rand(1,10);

% Create axes & store handles
h.myfig = figure;
h.ax1 = axes('Parent', h.myfig, 'Box', 'off');
h.ax2 = axes('Parent', h.myfig, 'Position', h.ax1.Position, 'Color', 'none', 'YAxisLocation', 'Right');

% Preserve axes formatting
hold(h.ax1, 'on');
hold(h.ax2, 'on');

% Plot data
plot(h.ax1, x, x);
plot(h.ax2, x, y);

Box . , , .

Position , . , , R2014b, , h.ax1.Position get(h.ax1, 'Position').

Color YAxisLocation .

hold . , reset , .

, !

+1

Matlab 2016a yyaxis. :

x = linspace(0,10);
y = sin(3*x);
yyaxis left
plot(x,y)

z = sin(3*x).*exp(0.5*x);
yyaxis right
plot(x,z)
ylim([-150 150])

0

Source: https://habr.com/ru/post/1616375/


All Articles