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?
$\begingroup$
$\endgroup$
1
2 Answers
$\begingroup$
$\endgroup$
2
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}]
Graphics[{FaceForm[Opacity[.5, Yellow]], Polygon@a,
AbsolutePointSize[20], Thickness[.02],
Through[{Point, Line}[a, VertexColors -> colors]]}]
-
-
$\begingroup$ @ChonglinZhu, my pleasure. Welcome to mma.se. $\endgroup$– kglrCommented Nov 6, 2018 at 22:15
$\begingroup$
$\endgroup$
4
Graphics[{Red, PointSize[0.05], Point /@ a}]
or
Graphics[{Red, PointSize[0.05], (Point /@ a), Green, Line[a]}]
-
$\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$ 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$ 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
Polygon
you do not need to close the path, i.e., eitherPolygon[Most[a]]
orPolygon[Rest[a]]
will each draw thePolygon
. If you want an unfilled polygon thenLine[a]
will need a closed path. $\endgroup$