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.

Ticks is an option for Gauges. I fail, however, to apply custom Ticks to Gauges. For instance, compare these two:

 {ThermometerGauge[50, {0, 100}, Ticks -> Automatic], 
 ThermometerGauge[50, {0, 100}, Ticks -> {0, 50, 100}]}

What you see is this:

enter image description here

No difference!

I also tried with the Horizontal- and VerticalGauge with the same success.

Do you know a workaround?

EDIT 11.07.13: I have seen the answers to my question. They all are good and fascinating, and in another case I will certainly use them. They do not answer my question though. For this reason I would like to give some more explanation of what I am really after. I will give it within an example of a different problem, where it is easy to obtain such a result.

So let us consider two simple plots. First is this

Plot[x, {x, -0.3, 0.3}, ImageSize -> 250]

second is this:

 Plot[x, {x, -0.3, 0.3}, Ticks -> {{0, 3/16, 1/4}, Automatic}, 
 ImageSize -> 250]

enter image description here

Here you can see it. The y axis in both plots is automatic - do not look at it. The x axis of the first plot is automatic for comparison, while the x axis of the second plot is what I am after. I would like to achieve the same on the ThermometerGauge, if possible by easy means. The easy means are here important, since looking at programs below I feel that it is easier to draw such a Gauge from scratch. For example, like this:

  thermo[x_] := Show[{
   Graphics3D[{Text[Style["-0.3", 12], {-0.15, 0, -0.3}], 
     Text[Style["0", 12], {-0.15, 0, 0}],
     Text[Style["3/16", 12], {0.14, 0, 3/16}] , 
     Text[Style["1/4", 12], {0.15, 0, 0.25}] , 
     Text[Style["0.3", 12], {-0.13, 0, 0.3}]}, 
    ViewPoint -> {0, -1.5, 0}, Boxed -> False, 
    ImageSize -> {120, 300}],
   Graphics3D[{LightBlue, Specularity[White, 20], Opacity[0.5], 
     Sphere[{0, 0, -0.4}, 0.11]}],
   Graphics3D[{Red, Specularity[White, 20], 
     Sphere[{0, 0, -0.4}, 0.1]}],
   Graphics3D[{LightBlue, Opacity[0.5], 
     Tube[{{0, 0, -0.4}, {0, 0, 0.35}}, 0.05]}],
   Graphics3D[{Red, Specularity[White, 20], 
     Cylinder[{{0, 0, -0.45}, {0, 0, x}}, 0.04]}],

   Graphics3D[{Thickness[0.015], 
     Line[{{-0.07, 0, #}, {-0.09, 0, #}}] & /@ 
      Table[i, {i, -0.3, 0.3, 0.1}]}],
   Graphics3D[{Red, Thickness[0.015], 
     Arrow[{{0.09, 0, 3/16}, {0.03, 0, 3/16}}], 
     Arrow[{{0.09, 0, 0.25}, {0.03, 0, 0.25}}]}]
   }]

Try it:

Manipulate[
 thermo[x], {{x, 0}, -0.3, 0.3}]

It looks as shown here:

enter image description here

share|improve this question
    
Not sure what exactly you are after, but maybe this? ThermometerGauge[50, {0, 100}, ScaleDivisions -> 2] –  Pinguin Dirk Jul 10 '13 at 8:50
    
@PinguinDirk ScaleDivisions -> 2, hmm bug? :) –  Kuba Jul 10 '13 at 8:52
    
weird, indeed, 2 and 3 give the same result... –  Pinguin Dirk Jul 10 '13 at 8:54
    
@Pinguin Dirk good to know, thank you. But I need really custom ticks. I will write a manipulator with ThermometerGauge instead of slider, with the interval from, say, -0.3 to 0.3 such that there are ticks {0, 1/4, 3/16} only. –  Alexei Boulbitch Jul 10 '13 at 9:10
    
@Kuba: it seems that it is using something like FindDivisions to get the ticks, check e.g. 9 vs 10... Knowing that, it'll be tough exploiting this feature to get really "custom" ticks. Guess another approach is needed. –  Pinguin Dirk Jul 10 '13 at 9:27
show 1 more comment

3 Answers 3

Ticks does not appear to be an option for ThermometerGauge. (TicksStyle is.) You must use ScaleDivisions from what I can tell.

Mathematica seems to be making some aesthetic judgment about the request for 3 scale divisions. It won't divide {0,100}, {0, 99} or {0,90} into 3 divisions but it happily does so for the scales {0, 30} and {0,300}.

{ThermometerGauge[50, {0, 100}, ScaleDivisions -> 2],
 ThermometerGauge[50, {0, 100}, ScaleDivisions -> 3],
 ThermometerGauge[50, {0, 99}, ScaleDivisions -> 3],
 ThermometerGauge[50, {0, 90}, ScaleDivisions -> 3],
 ThermometerGauge[50, {0, 30}, ScaleDivisions -> 3],
 ThermometerGauge[50, {0, 300}, ScaleDivisions -> 3],
 ThermometerGauge[50, {0, 100}, ScaleDivisions -> 4],
 ThermometerGauge[50, {0, 100}, ScaleDivisions -> 5]}

thermometers

share|improve this answer
    
I'd suspect: FindDivisions[{0, 100}, #] & /@ {2, 3, 4, 5} resp FindDivisions[{0, 300}, #] & /@ {2, 3, 4, 5}, yields exactly these values –  Pinguin Dirk Jul 10 '13 at 10:13
    
It wants to avoid fractions :) –  Kuba Jul 10 '13 at 10:14
    
@David Carraher Thank you, it is a nice idea. Unfortunately, it does not answer my question. Probably such an answer does not exist. –  Alexei Boulbitch Jul 10 '13 at 11:28
    
Kuba, It's more than fractions. If you try to divide the scale {0,99} into 3, it also balks. –  David Carraher Jul 10 '13 at 13:01
    
Alexei, Ticks does not appear as an option for ThermometerGauge. –  David Carraher Jul 10 '13 at 13:08
show 2 more comments

I do not know any undocumented option but here is a solution:

static ThermometerGauge:

ticks[{s_, k_}, {p_, q_}] := ReplaceAll[#, {
 {{_, Scaled[{-0.1, _}, _]} ..} :> ({{0., #}, Scaled[{-0.1, 0}, {0., #}]
                                    } & /@Table[i/k, {i, s, k, (k - s)/p}]),
 {{_, Scaled[{-0.065, _}, _]} ..} :> ({{0., #}, Scaled[{-0.065, 0}, {0., #}]
                                      } & /@Table[i/k, {i, s, k, (k - s)/(p q)}]),
 {Text[___] ..} :> (Text[Round[k #, .1], Offset[{-3., 0.}, Scaled[{-0.1, 0.}, {0., #}]], 
                         {1, 0.}, {1, 0}] & /@ Table[i/k, {i, s, k, (k - s)/p}])
 }] &;

ThermometerGauge[33, {1, 99}] // ticks[{0, 99}, {3, 4}]

enter image description here

dynamic ThermometerGauge:

 ticks2[{s_, k_}, {p_, q_}] := ReplaceAll[#, {
 {{_, Scaled[{-0.1, _}, _]} ..} :> ({{0., #}, Scaled[{-0.1, 0}, {0., #}]
                                    } & /@Table[i/k, {i, s, k, (k - s)/p}]),
 {{_, Scaled[{-0.065, _}, _]} ..} :> ({{0., #}, Scaled[{-0.065, 0}, {0., #}]
                                      } & /@ Table[i/k, {i, s, k, (k - s)/(p q)}]),
 {Inset[___] ..} :> (Inset[Round[# k,.1], Offset[{-3., 0.}, Scaled[{-0.1, 0.}, 
                           {0., #}]], {1, 0.}, Automatic, {1, 0}
                          ] & /@ Table[i/k, {i, s, k, (k - s)/p}])
 }] &;

ThermometerGauge[Dynamic@x, {13, 123}] // ticks2[{13, 123}, {5, 5}]

enter image description here

share|improve this answer
add comment

another hack, turn them off and draw manualy..

Show[ {
  Graphics[
   { Text[#, {-.1, .01 #}]  , 
     Line[{{-.01, 0.01 #}, {-.065, .01 #}}]}]  &
               /@ Table[33 i , {i, 0, 3}] , 
    Graphics[ Line[{{-.01 , 0.01 #}, {-.065/2, .01 #}}] ] &
               /@ Table[3 i , {i, 0, 33}],
    ThermometerGauge[33, {1, 99}, ScaleDivisions -> 0]}]

enter image description here

note as a quick hack i didn't work out the exact scaling, but it looks right.

edit: more general version.

myguage[val_, {min_, max_}, nmaj_] := 
 Module[{tic, x0 = -.01, x1 = -.065},
  tic[y_, x0_, x1_] := Line[{{x0, y}, {x1, y}}];
  Show[{Graphics@{
      {
         Text[Round[# (max - min)/(nmaj - 1) + min, .01],
                 {1.8 x1, (#/(nmaj - 1))}],
         tic[(#/  (nmaj - 1)), x0, x1]
         } & /@ Range[0, nmaj - 1] ,
      ,
      tic[(#/(5  (nmaj - 1))), x0, x1/2] & /@ Range[0, 5  (nmaj - 1)]}
    ,
    ThermometerGauge[val, {min, max}, ScaleDivisions -> 0]}]]
myguage[72, {32, 212}, 7]

enter image description here

share|improve this answer
add comment

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.