Howto clip a scatter plot to axes with limits

111 ビュー (過去 30 日間)
Thomas
Thomas 2013 年 10 月 4 日
編集済み: Joseph Cheng 2015 年 3 月 11 日
Hi,
i have some scatter data and i'd like to scatterplot it with user defined axes limits and "equal axes" . However, if i do e.g.
[mgx mgy] = meshgrid(-60:60); %some example data
scatter(mgx(:), mgy(:));
xlim([-50 50]);
ylim([-50 50]);
axis equal;
the scatter data wont be clipped at the axes borders anymore. Whatever i do, i can't get the x/ylim AND the equal work at the same time with clipping. Interestingly the 'Clipping' property of the scattergroup remains 'on' all the time and changing it has no effect.
Any ideas how to do this? (I have Matlab 2011b)
  1 件のコメント
Thomas
Thomas 2013 年 10 月 4 日
No solution?

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

回答 (2 件)

Kevin Bartlett
Kevin Bartlett 2015 年 3 月 11 日
Sorry, no answer. I have the same problem:
scatter(1,1,1000,'r','filled','MarkerEdgeColor', 'k'); axis([0 1 0 1]); box on
  1 件のコメント
Joseph Cheng
Joseph Cheng 2015 年 3 月 11 日
編集済み: Joseph Cheng 2015 年 3 月 11 日
I don't think that is the same problem. You're plotting something on the edge snd its inclusive. The point in the scatter is representing (1,1) not the area of the red dot. (were you looking for a quarter circle still within (1,1)

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


Joseph Cheng
Joseph Cheng 2015 年 3 月 11 日
編集済み: Joseph Cheng 2015 年 3 月 11 日
Reverse the order that you're setting the parameters.
[mgx mgy] = meshgrid(-60:60); %some example data
scatter(mgx(:), mgy(:));
axis equal;
xlim([-50 50]);
ylim([-50 50]);
So my very quick perception of how it is doing this is that if you comment out the axis equal in the original post and see what comes up. You'll see that the x axis is longer already than the y axis. So by then calling axis equal it would then squash the x axis points to be square and not elongating the spaces in the y direction to equal x.
So by causing the spacings to be square then limiting the display you'd get what you'd like.
  2 件のコメント
Thomas
Thomas 2015 年 3 月 11 日
Wow, an answer to my 1.5year old question... i didn't even remember that problem anymore.
However, your solution produces:
And as you can sse, while the axes proportions are equal and the axes are limited, the scatterplot is not clipped correctly to the axes (which makes it useless for publishing)...
Joseph Cheng
Joseph Cheng 2015 年 3 月 11 日
編集済み: Joseph Cheng 2015 年 3 月 11 日
really because when i run it typed out i get
What version are you running. but i guess it doesn't matter. I don't think i ever came across anything that looked like that problem of plotting outside the axes even in earlier versions of the R2014a that i'm running now

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

カテゴリ

Help Center および File ExchangeScatter Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by