【发布时间】:2012-07-17 22:30:41
【问题描述】:
我正在尝试创建一个 matlab 绘图,其中有多个 x 轴一个在另一个之下,一个 y 轴。
我查看了 Mathworks 文件交换,只有多个 y 轴的建议/脚本。我想实现类似this question for R。
【问题讨论】:
-
也许其中之一可以帮助您:- Using Multiple X- and Y-Axes - linkaxes
我正在尝试创建一个 matlab 绘图,其中有多个 x 轴一个在另一个之下,一个 y 轴。
我查看了 Mathworks 文件交换,只有多个 y 轴的建议/脚本。我想实现类似this question for R。
【问题讨论】:
如果您只需要第二个轴来显示不同的比例,这是一个示例解决方案(Jeff_K 的解决方案,但更有效):
first_axis = gca;
sqz = 0.12; %// distance to squeeze the first plot
set(first_axis, 'Position', get(first_axis, 'Position') + [0 sqz 0 -sqz ]);
ax2 = axes('Position', get(first_axis, 'Position') .* [1 1 1 0.001] - [0 sqz 0 0],'Color','none');
scale_factor = 42; %// change this to your satisfaction
xlim(get(first_axis, 'XLim') * scale_factor);
set(ax2, 'XScale', get(first_axis, 'XScale')); %// make logarithmic if first axis is too
【讨论】:
如果您实际上不需要在辅助轴上绘制数据,而只是使用它们来显示比例(如您链接到的示例),您可以通过添加第二个(或第三个等)来完成。 ) 轴在适当的位置,并将高度设置得很小:
ax2 = axes('Position',[0.1 0.1 0.8 0.001],'Color','none')
然后适当地设置刻度标签。
【讨论】:
您需要为此使用补丁功能。 更多详情请看这里:http://www.mathworks.com/matlabcentral/fileexchange/26550-myplotyy
【讨论】: