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?
views:
576answers:
3
+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
2010-04-20 14:49:29
Thanks for this, although I find it weird that plotyy actually requires you to plot the data twice to get the desired effect.
AndyL
2010-04-20 15:44:14
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
2010-04-20 15:50:07
+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:
gnovice
2010-04-20 15:10:51