Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Left & Right yaxislocations with imagesc

Subject: Left & Right yaxislocations with imagesc

From: Mike Fowler

Date: 13 Mar, 2006 10:13:34

Message: 1 of 3

Hi folks,

I'm trying to plot using imagesc, and I would like to put (different)
y-axis labels on both the left and right y-axes, but haven't found
out how to do this yet.

The regular commands for plotting 2 y-axes (or plotyy) don't seem to
work here - the yaxislocation commands.

X = unifrnd(-1,1,11,11);
h11=imagesc(X,[-1 1]);
ax2 = axes('Position',get(ax1,'Position'),'YAxisLocation','right');
h21 = imagesc(flipud(test6),[-1 1]);

doesn't work as I want. It returns an error, and the yaxis to the
left side. I've managed to get left and right y-axis in a full figure
plot (not a subplot), through the Property Editor GUI, but need to
edit multiple subplots, and can't find the right syntax.
If anyone can help out here I'd be very grateful!


Subject: Left & Right yaxislocations with imagesc

From: Adam A

Date: 2 May, 2012 09:19:07

Message: 2 of 3

A very old post, but I've been looking for an answer to the same problem. Here's some code that can be used as a workaround:


% Create two axes:
h1 = axes;
h2 = axes;

% Place the imagesc data in axes h2:

% Label the axes:

% Create the colorbar:
hc = colorbar('vert');

% Make the two axes have matching dimensions:
temp1 = get(h1);
temp2 = get(h2);

Subject: Left & Right yaxislocations with imagesc

From: Adam A

Date: 2 May, 2012 11:06:09

Message: 3 of 3

Also, although the code above doesn't work with Matlab's subplot command, you can work around that by positioning the axes manually, by substituting in the lines below:

% Create two axes:
h1 = axes('Position',[0.1,0.6,0.8,0.3]);
h2 = axes('Position',[0.1,0.6,0.8,0.3]);

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us