Message Boards Message Boards

1
|
7761 Views
|
4 Replies
|
8 Total Likes
View groups...
Share
Share this post:

Control the appearance of Region graphics?

Reference the code below which discretises a geometric region (as shown in the accompanying graphic), I want to display node and face numbers with node numbers in one colour and face numbers in a different colour. However, I haven't been able to find a way of achieving this.

Also, I'd like to be able to control the default (blue) solid fill that's used to highlight the discretised region - ideally being able to specify no fill. This becomes an issue when I choose different fill colours for the cells and apply Opacity (low Opacity values result in the fill tending to the default blue rather than being almost opaque).

Any suggestions would be much appreciated.

Thanks in anticipation,

Ian

Region[Polygon[{{0, 0}, {15, 0}, {15, 2}, {10, 2}, {5, 5}, {0, 5}}]] //

  DiscretizeRegion[#
    , Frame -> True
    , FrameTicks -> {x, x} /. x -> Range[-20, 20, 1]
    , FrameLabel -> {"x-coordinate (m)", "y-coordinate (m)"}
    , GridLines -> {x, x} /. x -> Range[-20, 20]
    , GridLinesStyle -> Directive[LightGray, Thin]
    , ImageSize -> Full
    , MaxCellMeasure -> 0.5
    , MeshCellLabel -> {0 -> "Index", 2 -> "Index"}
    , MeshCellStyle -> {{2, All} -> 
       Directive[RGBColor[0, 0.75, 0.5, opacity]], {2, 1} -> {Yellow, 
        Opacity[opacity]}, {1, All} -> 
       Directive[GrayLevel[0.975], Thickness[Medium]], {0, All} -> 
       Directive[Red, PointSize[Large]]}
    (*,Method\[Rule]{"AxesInFront"\[Rule]True,
    "GridLinesInFront"\[Rule]True}*)
    , PlotRangePadding -> 1
    ] & /. {opacity -> 0.75(*0=transparent, 1=solid fill*)}

Mesh

POSTED BY: Ian Williams
4 Replies

Thanks both. Your suggestions have been a big help and are much appreciated. For future reference, a notebook illustrating how the stated objectives can be achieved is attached. Thanks again, Ian

Attachments:
POSTED BY: Ian Williams

To color the labels, you can use Placed, e.g.:

MeshCellLabel -> {0 -> Placed["Index", "Centroid", Style[#, Red] &], 
  2 -> Placed["Index", "Centroid", Style[#, Green] &]}

will make the point labels red and the face labels green.

POSTED BY: Carl Woll
Posted 6 years ago

Wow, very nice Carl!

Looks like we can feed Automatic into Placed to move the red labels off the vertices.

MeshCellLabel -> {0 -> Placed["Index", Automatic, Style[#, Red] &], 
  2 -> Placed["Index", "Centroid", Style[#, Green] &]}
POSTED BY: Greg Hurst
Posted 6 years ago

You could discretize beforehand and then refer to the cells explicitly.

mr = DiscretizeRegion[Polygon[{{0, 0}, {15, 0}, {15, 2}, {10, 2}, {5, 5}, {0, 5}}], MaxCellMeasure -> 0.5];

MeshRegion[mr
    , Frame -> True
    , FrameTicks -> {x, x} /. x -> Range[-20, 20, 1]
    , FrameLabel -> {"x-coordinate (m)", "y-coordinate (m)"}
    , GridLines -> {x, x} /. x -> Range[-20, 20]
    , GridLinesStyle -> Directive[LightGray, Thin]
    , ImageSize -> Full
    , MeshCellLabel -> Join[(# -> Style[Last[#], Blue]& /@ MeshCellIndex[mr,0]), (# -> Style[Last[#], Purple]& /@ MeshCellIndex[mr,2])]
    , MeshCellStyle -> {{2, All} -> 
       Directive[RGBColor[0, 0.75, 0.5, 0.75]], {2, 1} -> {Yellow, 
        Opacity[0.75]}, {1, All} -> 
       Directive[GrayLevel[0.975], Thickness[Medium]], {0, All} -> 
       Directive[Red, PointSize[Large]]}
    (*,Method\[Rule]{"AxesInFront"\[Rule]True,
    "GridLinesInFront"\[Rule]True}*)
    , PlotRangePadding -> 1
    ]

enter image description here

As for your other question, the only work around I can find is to add the option BaseStyle -> {FaceForm[]}. Then any face you want colored, you'll need to specify a FaceForm, e.g.

MeshCellStyle -> {..., {2, 1} -> {FaceForm[Yellow], Opacity[0.75]}, ...}

I'm not really sure why this is needed.

POSTED BY: Greg Hurst
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract