How can I set LineWidth property when using opengl?

I am trying to plot a few simple geometries. One of them with a color gradient which switches the renderer to opengl. A simple test script is below. The rectangle is first drawn with a wide line width, but then changed once the fill is drawn
clear all,close all
color1 = [1 1 0];
color2 = [1 0 0];
rh=rectangle('Position',[0 0 60 60],'LineWidth',30,'EdgeColor',[0.5 0.5 0.5]);
hold on
%%the following command will switch the renderer and change the rectangle line width
fh=fill([10 20 20],[10 5 15],1,'FaceColor','interp','FaceVertexCData', [color1;color2;color2],'LineStyle','none');

답변 (1개)

Image Analyst
Image Analyst 2014년 4월 28일
I believe fill() creates another graphics object in the overlay on top of the first one you drew with rectangle. Why don't you set the 'FaceColor' property of the rectangle? Though with an absurd line width of the edge of 30, with a rectangle that's only 60 high, you probably won't see the face unless you reduce the line width to something reasonable.
Try this:
color1 = [1 1 0];
color2 = [1 0 0];
rh = rectangle('Position',[0 0 60 60],...
'LineWidth', 15,...
'EdgeColor',[0 0.5 1], ...
'FaceColor', [1, 0, 1]);
hold on;
fh=fill([10 20 20],[10 5 15],1,'FaceColor','interp','FaceVertexCData', [color1;color2;color2],'LineStyle','none');% Enlarge figure to top half of the screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0.5 1 0.5]);
Does that do close to what you want?

댓글 수: 2

No, that doesn't do it. The LineWidth of the rectangle still gets reduced.
I wouldn't describe a LineWidth of 30 as absurd since it is measured in points whereas the canvas size might not. I just used a big number to clearly show the effect of it being reduced to something else when opengl kicks in. I could probably set the FaceColor and add a second smaller rectangle inside with the same color as the canvas, but that seems like a tedious workaround and I was wondering if there isn't a better solution.
Maybe you could post an image of what your desired output would look like to help us visualize.

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

카테고리

도움말 센터File Exchange에서 Graphics Performance에 대해 자세히 알아보기

태그

질문:

2014년 4월 28일

댓글:

2014년 4월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by