Scatter plot does not display point 0,0 when double precision

2 ビュー (過去 30 日間)
chris
chris 2014 年 4 月 23 日
コメント済み: AJ von Alt 2014 年 4 月 23 日
I have the following code which works as intended, plotting 3 points.
x = [0 0; 12 0; 6 6];
scatter(x(:,1), x(:,2), 100, 'fill');
However, when I interject the following line
x = 1.01 * x;
which effectively turns everything into double precision, then the point 0,0 does not display
why is that, and how can I make it so that it also displays?
Thanks in advance!

採用された回答

José-Luis
José-Luis 2014 年 4 月 23 日
Trying to understand the mess that is Matlab's graphics engine is a real pain. I can only recommend a workaround:
x = [0 0; 12 0; 6 6];
figure(1)
scatter(x(:,1), x(:,2), 100, 'fill');
x = 1.01 * x;
figure(2)
scatter(x(:,1), x(:,2), 100, 'fill'); %Now readjust the axes so you can see what you actually plotted:
set(gca,'XLim',x([1 2],1)); %you can use min() max() in order to avoid hard coding the indices.
set(gca,'YLim',x([1 3],2));

その他の回答 (3 件)

AJ von Alt
AJ von Alt 2014 年 4 月 23 日
This looks like an issue with the Painters renderer. Switching to OpenGL resolves the issue on my end.
x = [0 0; 12 0; 6 6];
figure('renderer','OpenGL')
scatter(x(:,1), x(:,2), 100, 'fill');
y = 1.01 * x;
figure('renderer','OpenGL')
scatter(y(:,1), y(:,2), 100, 'fill');
  2 件のコメント
chris
chris 2014 年 4 月 23 日
This also works! Although it goes beyond my ability to understand this, it is a cleaner solution. Thanks!
P.S. I think you need the
figure('renderer','OpenGL')
line only once, otherwise it creates an additional empty plot...
AJ von Alt
AJ von Alt 2014 年 4 月 23 日
The renderer is used to draw the plot in the figure. It is defined independently for each figure so you will need to specify it every time you create one.
You can change the renderer of the current figure to "OpenGL" using the command:
set( gcf , 'renderer' , 'OpenGL' )

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


chris
chris 2014 年 4 月 23 日
Thanks for your answer. Attached image is how my system behaves.

chris
chris 2014 年 4 月 23 日
This works! It is weird though why the original version doesn't behave seamlessly.
Anyways, thanks everybody for the help.

カテゴリ

Help Center および File ExchangeGraphics Object Properties についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by