Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I would like to use something like Point[x,y] to plot diamonds instead of small circles ("points"). I'm creating charts from scratch inside a Graphics expression using my own graphics functions. I've looked through the documentation and questions here and haven't found anything about how to do it.

share|improve this question
    
Have you looked at this? –  m_goldberg Aug 10 at 16:39
    
I've seen your icon, but it hadn't registered as an example of what I wanted to do. Did you use translate? –  George Wolfe Aug 10 at 16:43
    
Sorry, I don't understand what you mean by "your icon". I gave a link to a previous posted question that I think relevant to yours. –  m_goldberg Aug 10 at 16:47
    
@m_goldberg I believe he meant your SE avatar which is automatically generated. It has some rhombi in its corners. –  Jens Aug 10 at 23:13

3 Answers 3

up vote 3 down vote accepted

I use Translate for this purpose, which can not only translate along a single vector, but can create multiple copies translated along different vectors.

For example, let's use these (relative) positions:

points = RandomReal[10, {10, 2}]

Then

Graphics[
 Translate[Triangle[], points]
]

Mathematica graphics

Just make sure that your source object is centred around {0,0}, otherwise the plot will be misaligned, like here:

Graphics[
 {Translate[Triangle[], points],
  Red, PointSize[Large], Point[points]}
]

Mathematica graphics

I was just lazy to make a proper diamond so I use Triangle ...

share|improve this answer
    
Graphics[Translate[Rotate[Rectangle[], 45 Degree], points]] for diamonds? –  kguler Aug 10 at 16:19
    
@kguler That is not centred on {0,0}, so we get back to me being lazy to make a proper diamond ;-) –  Szabolcs Aug 10 at 16:22
    
@Szabolcs Yet another function I didn't know about. Translate seems pretty handy. It seems like it should work. –  George Wolfe Aug 10 at 16:38
    
@Szabolcs It works! Thanks. –  George Wolfe Aug 10 at 16:56

here some examples how to define your own PlotMarkers

plotmarkers = 
 colors // 
  Map[Graphics[{#, Disk[]}, ImageSize -> 8] // 
      ToString[#, FormatType -> StandardForm] & // Function, #] &
ListPlot[{{1, 2, 3, 5, 8}, {2, 3, 6, 9, 10}, {4, 5, 7, 10, 12}}, 
 PlotMarkers -> plotmarkers, PlotRange -> All, 
 PlotRangeClipping -> False]

plotmarkers = {Style["\[FilledDiamond]", 16, Lighter@Red], 
  Style["\[FilledDiamond]", 16, Lighter@Blue], 
  Style["\[FilledDiamond]", 16, Lighter@Green]}
ListPlot[{{1, 2, 3, 5, 8}, {2, 3, 6, 9, 10}, {4, 5, 7, 10, 12}}, 
 PlotMarkers -> plotmarkers, PlotRange -> All, 
 PlotRangeClipping -> False]

You may use Inset or Text to place them accordingly in Graphics, or if available the Option PlotMarkers -> yourPlotmarkers

PlotMarkers

plotmarkers = {Style["\[FilledDiamond]", 16, Lighter@Red], 
  Style["\[FilledDiamond]", 16, Lighter@Blue], 
  Style["\[FilledDiamond]", 16, Lighter@Green]}
point[x_, y_, which_] := Inset[plotmarkers[[which]], {x, y}]
Graphics[{point[1, 0, 1], point[-1, 0, 1], point[0, 1, 2], 
  point[0, -1, 2], point[0, 0, 3]}]

diamond2

share|improve this answer
    
+1 Pity that you don't show that the green diamond is at (0,0) :) –  eldo Aug 10 at 17:15

I would define a function diamond that draws diamonds centered at given point and with a specified bounding box.

diamond[xy : {x_, y_} : {0, 0}, wh : {w_, h_} : {1, 1}] := 
 Translate[Polygon[{{w/2., 0.}, {0., h/2.}, {-w/2., 0}, {0., -h/2.}}], xy]
Graphics[
  Table[{Hue[RandomReal[]], diamond[RandomReal[1, {2}], RandomReal[.2, {2}]]}, {200}]]

diamonds

share|improve this answer
    
How does the syntax [xy : {x_, y_} : {0, 0} work? Is it like a chain of defaults? –  George Wolfe Aug 11 at 0:22
1  
@GeorgeWolfe. It does look like a chain of defaults, but it isn't. The full-form of the first argument to diamond is Optional[Pattern[xy, List[Pattern[x, Blank[]], Pattern[y, Blank[]]]], List[0, 0]], so it can be read (<pattern-name> : <pattern>) : <default>. Colon ( : ) is one of few operators in Mathematica that is interpreted differently according to context. The first colon is interpreted as the infix form of Pattern and the second as the infix form of Optional. –  m_goldberg Aug 11 at 2:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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