0
votes

I have plotted two curves using plotyy function of MATLAB:

[AX,H1,H2] = plotyy(voltage_span, amplitude,voltage_span, Ca_SR);

The problem is that I cannot change the color and font of the second axis(the right one). The following figure is the the output of my plotyy function. enter image description here

MATLAB help states that for changing the axes's label, one should use the followings:

set(get(AX(1),'Ylabel'),'String','Slow Decay') 
set(get(AX(2),'Ylabel'),'String','Fast Decay')

So, I tried the following commands(which doesn't work):

set(get(AX(2),'YColor'),[1 0 1]); % MATLAB gives ERROR! Invalid handle object.

If one enters get(AX(2)), they can see all the properties of the right axis which seems not to have color property. So I am wondering where is the problem and how to change the color and font size of the right axis(?)

2

2 Answers

2
votes

To change the font size of the right axis, enter the following code:

set(AX(2),'YColor', [1 0 0]); % Change the right Axis's color to red
set(AX(2),'FontSize', 20); % Change the right Axis's font size to 20

"YColor" property is the color of the right axis. Ax(2) holds the handle to the right axis(and Ax(1) to the left axis).

You might ask why the following does not work:

set(get(AX(2),'YColor'),[1 0 1]);

The reason is that "YColor" is not a handle and

get(AX(2),'YColor') 

simply returns the color of the right axis (which is light green by default):

>> get(AX(2), 'YColor')

ans =

         0    0.5000         0

However, for changing the left axis' label, you should write this:

set(get(AX(2),'Ylabel'),'String','Fast Decay')

Because 'Ylabel' property actually contains a handle to the label object.

By the way, to remove the XTicks of the right axis, do this:

set(AX(2),'XTick', []);
1
votes
set(AX(1), 'YColor', [0 1 0])
set(AX(2), 'YColor', [1 0 1])