Emma
Emma

Reputation: 618

second y-axis on pcolor plot

Is it possible to prodce a pcolor plot with 2 yaxis?

Consider the following example:

clear all
temp =  1 + (20-1).*rand(365,12);
depth = 1:12;
time =1:365;

data2 = 1 + (60-1).*rand(12,1); 
time2 = [28,56,84,124,150,184,210,234,265,288,312,342];

figure;
pcolor(time,depth,temp');axis ij; shading interp
hold on 
plot(time2,data2,'w','linewidth',3);

Instead of plotting the second dataset on the same y axis I would like it to placed on its own y-axis. Is this possible?

Upvotes: 3

Views: 2532

Answers (2)

yuk
yuk

Reputation: 19870

You need to add additional axes on the top of pcolor axes, match their position and then plot. You can set axes location on the top (X) and on the right (Y). Don't forget to link X axes if they suppose to match with LINKAXES.

pcolor(time,depth,temp');axis ij; shading interp
ax1 = gca;
%# new axes with plot
ax2 = axes('position',get(ax1,'position'),'color','none');
set(ax2,'YAxisLocation','right', 'XAxisLocation','top')
hold on
plot(ax2,time2,data2,'w','linewidth',3);
hold off
linkaxes([ax1 ax2], 'x');

pcolor with line

Upvotes: 1

Andrey Rubshtein
Andrey Rubshtein

Reputation: 20915

I am not sure what you mean. If you want same axes but different y values, try plotyy. If you want two different axes, try using the command subplot.

Upvotes: 0

Related Questions