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 want to create a series of plot markers which are circles, squares etc. with 2-3 letter codes centered within the marker. My current attempt looks like this:

{
t4dot =  Graphics[{Green, Disk[{0, 0}, ImageScaled[0.07]], 
          Style[Text["T4"], Yellow, Bold, 18]}],
gk1dot = Graphics[{Red, Rectangle[{0, 0}], 
          Style[Text["Gk1", {0.5, 0.5}], Yellow, Bold, 14]}]
}

which makes:

enter image description here

The "T4" marker is about right (although the centering is an issue). Obviously, I haven't been able to get rectangle[] to scale properly. When I tried to use these graphics as plot markers the circle and rectangle were huge and swamped the graph whilst the text stayed the same size.

I am aiming to make markers for which the graphics primitive and the text are nicely centered and scale as a group. I want to be able to call the resulting graphics with something like:

ListPlot[{{5, 7}, {4, 6}}, PlotMarkers -> {{t4dot, 16}, {gk1dot, 18}},
  PlotRange -> {{3, 6}, {3, 8}}, ImagePadding -> 35]

Any ideas about how to achieve this?

Also, I have looked here and here and I noticed that Mathematica often offsets the text towards the top-left corner of the graphic. Is there a way to overcome this?

share|improve this question
1  
Have a look here: mathematica.stackexchange.com/a/18828/131. Might be considered borderline duplicate (as already linked by yourself). –  Yves Klett Apr 11 '13 at 8:58
    
@YvesKlett, Yes, it is borderline. I think I can make the solution in that post work for me (but it's not ideal). The main downfall is that it still doesn't center the text nicely and cannot be applied to specific plotmarker shapes. For example, if I have a long piece of text I cannot see a way of using Framed[] to make a square around it (it would be nice to be able make diamonds as well!). –  geordie Apr 11 '13 at 9:42
    
Understood - just wanted to point you there in case this helped right away. As for the centering, I feel Framed does not do too bad, but perhaps you can come up with a really bad example... –  Yves Klett Apr 11 '13 at 11:03

1 Answer 1

up vote 3 down vote accepted

You have to center the Rectangle at {.5, .5}, and you also have to have two datasets. Simply feeding {{5, 7}, {4, 6}} is interpreted by ListPlot as a single dataset. For clarity, I've added some extra points.

t4dot = Graphics[{Green, Disk[{0, 0}, (ImageScaled@.07)], 
     Style[Text["T4", Offset@{2, -1}], Yellow, Bold, 18]}];
gk1dot = Graphics[{Red, Rectangle[ImageScaled[{.5,.5}-.07], ImageScaled[{.5,.5}+.07]], 
     Style[Text["Gk1", Offset@{2, -1}], Yellow, Bold, 14]}];

ListPlot[{{{4, 6}, {5, 7}}, {{4, 3}, {5, 2}}}, 
 PlotMarkers -> {{t4dot, 1}, {gk1dot, 1}}, 
 PlotRange -> {{3, 6}, {1, 8}}, ImagePadding -> 35]

enter image description here

share|improve this answer
    
Your solution looks good, unfortunately, your definition for gk1dot throws up errors for me. I'm running 8.0.4 on a Mac-SL –  geordie Apr 11 '13 at 9:36
    
@geordie It was just missing a bracket due to editing. Corrected now. –  István Zachar Apr 11 '13 at 9:40
    
Many thanks. The centering is still slightly variable. Is there a way to 'force' mathematica to get it dead center (or am i opening a graphical can of worms)? –  geordie Apr 11 '13 at 9:47
    
@geordie I think you always have to manually finetune these kind of things, but I may be wrong. The links you have included show some other solutions, e.g. with Inset. Might be rewarding to experiment with it. –  István Zachar Apr 11 '13 at 11:25

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.