tags:

views:

576

answers:

3

I plot a single trace in MATLAB with plot(). I'd like to add a right-y axis with a different set of tick marks (scaled linearly). Is this possible?

+4  A: 

You may try this submission to MATLAB File Exchange - PLOT2AXES.

PLOT2AXES example

yuk
+1  A: 

Open MATLAB Help with F1 and take a look at the functions below function plot which you mentioned, there you will see plotyy. This is what you probably need.

UPDATE: actually plotyy is NOT the answer to the question as pointed by gnovice.

Mikhail
Thanks for this, although I find it weird that plotyy actually requires you to plot the data twice to get the desired effect.
AndyL
The PLOTYY function plots *two* lines, each with their own y scale. In order to get *one line with two y scales* you'd probably have to do a couple tricky things (like plotting two lines, scaling the second one to the desired range, then making it invisible).
gnovice
+2  A: 

There are a number of good suggestions on this closely related question, although they deal with a more complicated situation than yours. If you want a super-simple DIY solution, you can try this:

plot(rand(1,10));       %# Plot some random data
ylabel(gca,'scale 1');  %# Add a label to the left y axis
set(gca,'Box','off');   %# Turn off the box surrounding the whole axes
axesPosition = get(gca,'Position');          %# Get the current axes position
hNewAxes = axes('Position',axesPosition,...  %# Place a new axes on top...
                'Color','none',...           %#   ... with no background color
                'YLim',[0 10],...            %#   ... and a different scale
                'YAxisLocation','right',...  %#   ... located on the right
                'XTick',[],...               %#   ... with no x tick marks
                'Box','off');                %#   ... and no surrounding box
ylabel(hNewAxes,'scale 2');  %# Add a label to the right y axis

And here's what you should get:

alt text

gnovice

related questions