linkaxes does not work like expected (or hoped)

Hi,
i wrote the following (minimal) code:
clear all
close all
X = -3:0.3:3;
a = 1;
b = 2;
c = 1;
Y = a + b * (X - c).^2 + 0.4* rand(1,length(X));
h = figure;
a1 = gca;
a2 = axes('xaxislocation','top','yaxislocation','right','color','none');
hold on
hData = scatter(X,Y);
linkaxes([a1 a2]);
axis([a1 a2], [min(X) max(X) min(Y) max(Y)])
hold off
Apparantly, I wanted to have a graph with axes on all 4 sides. I thought with "linkaxes" i can link the axes in a way that they are always scaled in the same way. For the x-axes it seems to work well, but the y-axes appears to have some different scaling factors (which you can see, if you resize a little bit the graph-window.
Can anybody explain what i did wrong?
Thanks!

3 件のコメント

Adam
Adam 2014 年 8 月 17 日
Your code works fine for me for both x and y axes on resizing.
Benjamin
Benjamin 2014 年 8 月 17 日
編集済み: Benjamin 2014 年 8 月 17 日
They have the same range. this works also perfect for me. Just the length of the axes is different. In the picture you can see what i mean (eg. the "30" left and right is not at the same heigth.... now i also saw that the data are going down below the graph.
EDIT: now also with the promised graph :-)
dpb
dpb 2014 年 8 月 17 日
Can't reproduce that effect here--what Matlab release and OS? Perhaps try changing the renderer setting if it's somehow related to a local video driver issue.

サインインしてコメントする。

 採用された回答

Benjamin
Benjamin 2014 年 8 月 17 日

0 投票

Matlab R2011b and Windows 8. I could solve the problem by adding
set(a1, 'Position', [0.13 0.13 0.74 0.74]);
set(a2, 'Position', get(a1, 'Position'));
I was just thinking "linkaxes" is doing that automatically

1 件のコメント

dpb
dpb 2014 年 8 月 17 日
Probably a version enhancement/bug fix since that release.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGraphics Performance についてさらに検索

タグ

質問済み:

2014 年 8 月 17 日

コメント済み:

dpb
2014 年 8 月 17 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by