如何更改Plotyy的第二轴的颜色和字体大小? [英] How to Change the Color and Font Size of the Seond Axis of Plotyy?

查看:928
本文介绍了如何更改Plotyy的第二轴的颜色和字体大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用MATLAB的plotyy函数绘制了两条曲线:

I have plotted two curves using plotyy function of MATLAB:

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

问题是我无法更改第二个轴(右侧)的颜色和字体.下图是我的plotyy函数的输出.

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.

MATLAB帮助指出,要更改轴的标签,应使用以下内容:

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.

如果输入get(AX(2)),他们可以看到右轴的所有属性,这些属性似乎没有颜色属性.所以我想知道问题出在哪里以及如何更改右轴的颜色和字体大小(?)

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(?)

推荐答案

要更改右轴的字体大小,请输入以下代码:

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"属性是右轴的颜色. Ax(2)将手柄保持在右轴(Ax(1)保持在左轴).

"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]);

原因是"YColor"不是句柄,并且

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')

因为"Ylabel"属性实际上包含标签对象的句柄.

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

顺便说一句,要删除右轴的XTicks,请执行以下操作:

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

set(AX(2),'XTick', []);

这篇关于如何更改Plotyy的第二轴的颜色和字体大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆