Message Boards Message Boards

0
|
7965 Views
|
5 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Plotting vector points efficiently?

Posted 8 years ago

Is there a better way of plotting a series of vector points (x,y) than using the Graphics[] command, see attached. I am just trying to visualize all the individual vector points to get an idea of the total graph; however my method seems awful crude and not very visually appealing?

p1=Graphics[{PointSize[Large],Black,Point[{0,0}],Text["(0,0)",{0,0.1}]}];
p2=Graphics[{PointSize[Large],Black,Point[{4,0}],Text["(4,0)",{4,0.1}]}];
p3=Graphics[{PointSize[Large],Black,Point[{4,2}],Text["(4,2)",{4,2.1}]}];
p4=Graphics[{PointSize[Large],Black,Point[{0,2}],Text["(0,2)",{0,2.1}]}];

Show[p1,p2,p3,p4]
Attachments:
POSTED BY: Mitchell Sandlin
5 Replies

I'm late but I believe the labelling here should satisfy a more elegant approach.

pts = {
   {0, 0}, {4, 0}, {4, 2}, {0, 2}
   };

Graphics[{
  {PointSize[Large], Point[pts]},
  Inset[#, # + {0, 0.2}] & /@ pts
  }]

Alternatively, moving away from Graphics,

ListPlot[Labeled[#, #] & /@ pts, Axes -> False]

and generally, for any list of vectors

plotVec = 
  Function[{pts}, 
   ListPlot[Labeled[#, #] & /@ pts, Axes -> False, PlotRange -> All]];

all produce the same output.

POSTED BY: Benjamin Goodman

Hi Ben,

you are right. But your labels contain curly brackets. Much of my labelling code is to replace them by round ones. Also I was not sure whether it was relevant that the labels be text like in the OP. I also wanted to maintain the Graphics structure.

Your Graphics suggestion with the parenthesis replaced could look like this:

pts = {{0, 0}, {4, 0}, {4, 2}, {0, 2}};

Graphics[{{PointSize[Large], Point[pts]}, 
  Inset[StringReplace[
      ToString[#], {"{" -> "(", "}" -> ")"}], # + {0, 0.2}] & /@ pts}]

or this if the Text is not required:

Graphics[{{PointSize[Large], Point[pts]}, Inset[MatrixForm[{#}], # + {0, 0.1}] & /@ pts}]

Cheers,

M.

POSTED BY: Marco Thiel

Ah, I missed the detail of the parenthesis vs. brackets in the OP. Thanks.

POSTED BY: Benjamin Goodman

You may try ListPlot with Labeled:

pts = {{0, 0}, {1/2, 1/2}, {1, 1}};
ListPlot[Map[Labeled[#, TraditionalForm[{#}]] &, pts]]
POSTED BY: Gianluca Gorni

Hi,

if this is a list of points:

list = {{0, 0}, {4, 0}, {4, 2}, {0, 2}};

then this would generate your plot:

Graphics[{PointSize[Large], Black, Point[#], Text["(" <> StringTake[ToString[#], 2 ;; -2] <> ")", # + {0, 0.1}]} & /@ list]

enter image description here

Cheers,

Marco

PS: The labelling can be done more elegantly.

POSTED BY: Marco Thiel
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