필터 지우기
필터 지우기

Bug in pcolor?

조회 수: 7 (최근 30일)
Muhlbauer
Muhlbauer 2011년 12월 30일
편집: user20912 2021년 5월 6일
Hi,
Whenever I use pcolor for a checkerboard plot the lines of my x-axis and y-axis disappear. This problem can be reproduced even with the example in the matlab help!
Try this (looks OK):
figure;
pcolor(hadamard(20))
colormap(gray(2))
shading flat;
axis ij
axis square
and compare against this (x,y axis disappears):
figure;
pcolor(hadamard(20))
colormap(gray(2))
shading flat;
axis ij
For whatever reason using pcolor together with shading flat makes the axis disappear (only the axis on the bottom and left of the plot). Why is that and why does using the axis square command make a difference?
In principle the axis square command would fix the problem but I don't want my axes to be square. Using axis normal instead does NOT fix the problem...
Any ideas?
  댓글 수: 2
Walter Roberson
Walter Roberson 2011년 12월 30일
It took me a moment to see what you were describing; the solid line on the top and right sides are not present with a plain pcolor() if the OpenGL renderer is in effect. painters and zbuffer renderer do not have this difficulty.
Image Analyst
Image Analyst 2011년 12월 31일
I was wondering why you're using pcolor() in the first place instead of image(). Do you know it's going to display a 19x19 grid and not a 20x20 grid? And the color of the tile in pcolor is not the value of the array you're displaying? When I ask I never have gotten a reason, all I get is people either not answering at all, or they say "No I never realized pcolor did that. That's not what I want."

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2011년 12월 30일
It is not a problem of pcolor, but a bug in the OpenGL renderer. It appears in the standard 2D-view and with enabled stretch-to-fill behaviour (DataAspectRatioMode, PlotBoxAspectRatioMode, CameraViewAngleMode set to 'auto'): Rounding errors influence the clipping and lines of the box disappear for some combinations of axes size in pixels and limits of the axes. In addition the X-ticks appears at bad positions.
Workaround: Rotate the axes object by a tiny angle, which move the objects by less than a pixel:
% Display the problem:
figure('Renderer', 'OpenGL', 'Position', [360, 502, 560, 420]);
AxesH = axes;
pcolor(hadamard(20))
colormap(gray(2))
shading('flat');
pause(1);
% Fix the problem:
set(AxesH, 'CameraUpVector', ...
[-sin(0.0001), cos(0.0001), 0] .* get(AxesH, 'DataAspectRatio'));
Using the ZBuffer or Painters renderer is a simple and nice workaround, if you do not need transparency in the plot.
Changing the YLimits by some eps value works sometimes, but I have not been able to identify the underlying pattern. The consideration of the DataAspectRatio is important, because:
set(AxesH, 'CameraUpVector', [-sin(0.0001), cos(0.0001), 0]) % BAD!
can have very strange effects to the positions of the X- and Y-labels.
This bug existed in Matlab 6.5 already, so you are in touch with a very solid history.
  댓글 수: 1
Jan
Jan 2011년 12월 30일
See: http://www.mathworks.nl/matlabcentral/newsreader/view_thread/293598

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

user20912
user20912 2020년 11월 21일
편집: user20912 2021년 5월 6일
This is really old but in case anyone looking for a nice solution, just use
set(gca,'layer','top','Box','on');

Muhlbauer
Muhlbauer 2012년 1월 3일
Jan,
I see what you did and it helps sometimes as a workaround. However, if I use the imagesc function instead of pcolor then I don't run into this issue. So, I still think there must be something wrong with the pcolor function too.
  댓글 수: 1
Jan
Jan 2012년 1월 3일
It happens with LINE also, and to be exact, even *without* LINE:
figure('Renderer', 'OpenGL');
AxesH = axes('Units', 'pixels', 'Position', [40, 40, 200, 200], ...
'YLim', [0, 20.7], 'Box', 'on', 'XGrid', 'on', 'YGrid', 'on');
This shows, that it only depends on the limits and the extent of the AXES. PCOLOR is not the problem.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by