How to prevent plotted contents to spill outside of the axes lines

Using
set(gca, 'Layer', 'top')
I end up with this:
Is there a way to completely hide plotted contents that appear beyond the axes?

4 件のコメント

Mitsu
Mitsu 2021 年 8 月 8 日
I also tried uistack(axisHandle,'top') , but it seems to be for other things and not applicable to this.
Yazan
Yazan 2021 年 8 月 8 日
編集済み: Yazan 2021 年 8 月 8 日
The data looks like it is spilling outside the axes space because the size of the markers is large compared to the size of the figure (or axes). You just need to reduce the marker size or increase the figure size.
Mitsu
Mitsu 2021 年 8 月 8 日
Thank you for your comment, Yazan. I am aware that I can always change the size of markers and lines, but that is not what I asked. I made them very big in this example to make it obvious for the purpose of this question.
Yazan
Yazan 2021 年 8 月 8 日
The property SizeData of a scatter plot is related to the area of the marker. So assuming you specify a circular marker, Matlab will plot circles centered at the data with a radius that can be computed from SizeData. So, for each data point, find the radius of the circular marker, compute the edge points locations (horizontal and vertical extensions of the marker), see if they exceeded the axis limits and discard the data point if so. This is unnecessarily complex in my opinion given that you just need to resize the axes to solve the issue.

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

回答 (2 件)

DGM
DGM 2021 年 8 月 8 日
編集済み: DGM 2021 年 8 月 8 日

1 投票

One would think that the 'clipping' property of the axes object would take care of that, but I guess not.
Oof:
I don't know if that's a very practical approach, especially for as many markers as you have. It might be better to just adjust your axes limits a bit instead.
Alexandra Molcanova
Alexandra Molcanova 2024 年 5 月 4 日

0 投票

this worked for me:
set(gca,'ClippingStyle','rectangle');
hope it helps :)

1 件のコメント

Interesting.
% some fake data
x = rand(100,1);
y = rand(100,1);
% it doesn't seem to work with scatter() objects
scatter(x,y,500,'filled')
set(gca,'ClippingStyle','rectangle');
grid on
% but it does work when using plot()
figure
plot(x,y,'.','markersize',80)
set(gca,'ClippingStyle','rectangle');
grid on

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

カテゴリ

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

製品

リリース

R2018b

タグ

質問済み:

2021 年 8 月 8 日

コメント済み:

DGM
2024 年 5 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by