Frage

I've written a program that creates a grid of hexagons, some black, some white. This is done randomly. I then choose randomly a subset of hexagons on the edges of which to place red diamonds. This script is designed to build pretend rock microstructures with grains (hexagons) and pore spaces (diamonds) for materials modeling. I'm using the fill() command to create each shape. The problem is that when I fill in the red diamonds, the edge of the hexagon beneath it is still showing through. I tried to post an image, but since this is my first time posting, it won't let me. I can email though, if anyone wants to see.

So to create the black hexagons:

h= fill(hexXY(i,j,1)+vx,hexXY(i,j,2)+vy,'k');

set(h,'edgecolor','k')

where the hexXY matrix holds x and y coordinates for the center of the hexagon, which added to the vx and vy arrays gives the vertices of each point on the hexagon. I then do the same thing with the diamonds:

h=fill(hexXY(i,j,1)+dvx,hexXY(i,j,2)+dvy,'r');

set(h,'edgecolor','r')

But, as I said, the black edges of the hexagons show through the red. I provided the vertices in order like you would draw them, though I don't think that should matter. I tried uistack and using patch, but neither worked for me. I can't set the hexagon edge color to none, because I have also have white hexagons, and if I set the background color to black I'd get black lines between the white hexagons. I removed have to remove the edge from either black or white hexagons, because where the two touch, the edges give messy pixelation.

Can anyone help me figure out how to get the red diamonds filled in properly?

EDIT: I didn't mention before, that this only occurs while saving the figure.You can't see it in the figure window. I've tried using print() and hgexport(), and changing the renderer, to no avail. Here is a small example with numbers pulled from my code to run:

hold on
v1=[0.3929 0.4107 0.3929 0.3571 0.3393 0.3571];
v2=[0.6907 0.6598 0.6288 0.6288 0.6598 0.6907];
h= fill(v1,v2,'k');
set(h,'edgecolor','k')

v3=[0.3750 0.3929 0.3750 0.3571 0.3750];
v4=[0.6366 0.6288 0.6211 0.6288 0.6366];
h=fill(v3,v4,'r');
set(h,'edgecolor','r')

set(gca,'position',[0 0 1 1],'units','normalized')
set(gcf,'PaperUnits','Inches','PaperPosition',[0 0 5 5]);
hgexport(gcf, 'test', hgexport('factorystyle'), 'Format', 'tiff','Resolution',600);

Here is the image saved with hgexport:

enter image description here

War es hilfreich?

Lösung

Try making your edges transparent:

set(h,'edgealpha',0)

Something weird is causing the original problem. If the commands are kept simple, everything appears fine:

h1= fill([1,2,3,3,2,1],[2,4,3,2,0,1],'m');
set(h1,'edgecolor','m')

hold on
h2= fill([2,3,2.5],[2,1,pi],'g');
set(h2,'edgecolor','g')

But the background edge moves forward when the foreground triangle is changed.

set(h2,'edgealpha',0) % an example of what can cause the problem to appear.

I don't know what's causing that.

Andere Tipps

If set(h,'edgealpha',0) does not work (as suggested by @user1739107), you may try set(h,'edgecolor','none').

On OSX R2012b, both solutions work fine.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top