1
$\begingroup$

say we have the list of points a = {{1, 1}, {2, 1}, {2, 2}, {1, 2}, {1, 1}},it is a simple square, how can we make color the nodes( in which that the nodes and the color on them are clearly seen and stand out from the vertexes), also this step will not affect the subsequent coloring of the edges and the interior?

$\endgroup$
1
  • $\begingroup$ For a Polygon you do not need to close the path, i.e., either Polygon[Most[a]] or Polygon[Rest[a]] will each draw the Polygon. If you want an unfilled polygon then Line[a] will need a closed path. $\endgroup$
    – Bob Hanlon
    Commented Nov 7, 2018 at 0:56

2 Answers 2

2
$\begingroup$

You can also use VertexColors:

colors = {Red, Green, Blue, Orange, Red};
Graphics[{FaceForm[Opacity[.5, Yellow]], Polygon@a,
  AbsolutePointSize[20], Point[a, VertexColors -> colors], 
  Thick, Gray, Line@a}]

enter image description here

Graphics[{FaceForm[Opacity[.5, Yellow]], Polygon@a,
  AbsolutePointSize[20], Thickness[.02],
  Through[{Point, Line}[a,  VertexColors -> colors]]}]

enter image description here

$\endgroup$
2
  • $\begingroup$ Thanks! This is so helpful! $\endgroup$ Commented Nov 6, 2018 at 22:14
  • $\begingroup$ @ChonglinZhu, my pleasure. Welcome to mma.se. $\endgroup$
    – kglr
    Commented Nov 6, 2018 at 22:15
0
$\begingroup$
Graphics[{Red, PointSize[0.05], Point /@ a}]

or

Graphics[{Red, PointSize[0.05], (Point /@ a), Green, Line[a]}]

enter image description here

$\endgroup$
4
  • $\begingroup$ Thanks! This is very useful, but how to color the four nodes differently use different colors? $\endgroup$ Commented Nov 6, 2018 at 20:23
  • $\begingroup$ I am having difficulty with understanding what you asking. 1) Why do you give a list of five pairs to define a square when four will do? 2) You seem to make a distinction between nodes and vertexes. Could you make that distinction clear? 3) You mention coloring edges at some later time. That and other things mentioned make me ask: are you concerned more about a graph theory object than about graphics object? Please edit your question to put me straight. $\endgroup$
    – m_goldberg
    Commented Nov 6, 2018 at 20:37
  • $\begingroup$ Also, it would be very useful if you add an image showing how the final result should look. $\endgroup$
    – m_goldberg
    Commented Nov 6, 2018 at 20:38
  • $\begingroup$ (1): By five points I meant to draw a closed polygon, as you can see the last point is the same as the first point,.I want to paint the edges and the nodes at the same time, and without the two affecting each hopefully, and I do not know if I can do all these in a nested "Polygon" function, Therefore $\endgroup$ Commented Nov 6, 2018 at 22:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.