1
$\begingroup$

I want to have a function plotnumber[number_, size_] that produces a number of chosen size.

My current solution is to use an empty plot.

plotnumber[n_, size_, ImSize_] := 
  Plot[, {x, 0, 1}, 
   Axes -> False, PlotLabel -> Style[n, size], ImageSize -> ImSize];

but this produces an ugly result because the label of a plot always stays on top and I don't have centered picture.

Any suggestions?

$\endgroup$
3
  • 7
    $\begingroup$ maybe plotnumber[n_, size_, ImSize_] := Graphics[Text[Style[n, size]], ImageSize -> ImSize]? $\endgroup$ – kglr Dec 16 '17 at 10:24
  • $\begingroup$ plotn[n_,siz]:=Style[ToString[n], FontSize ->siz] $\endgroup$ – bill s Dec 16 '17 at 20:51
  • $\begingroup$ @kglr that rocks, thank you!! $\endgroup$ – Veliko Dec 17 '17 at 18:22
1
$\begingroup$

A variant with some styling embellishments:

ClearAll[plotnumber]
plotnumber[o : OptionsPattern[]][n : (_Integer | _String | _Symbol), size_, ImSize_] := 
 Graphics[Text[Style[n /. x:(_Integer|_Symbol) :> ToString[x], ## & @@ size]], 
  ImageSize -> ImSize, o]

Examples:

options = Sequence[Frame -> True, FrameTicks -> False, ImagePadding -> 1];

The first argument can be Integer, String or Symbol:

plotnumber[options][#, {128, Red , FontFamily -> "SegoeScript"}, 200] & /@ 
 {3, "3", "A", A} // Row

enter image description here

Font size in printer units:

plotnumber[options][3, {#, Red , FontFamily -> "SegoeScript"}, 200] & /@
 {16, 32, 64, 128} // Row

enter image description here

Scaled font sizes:

plotnumber[options][3, {FonrtSize -> #, Red , FontFamily -> "SegoeScript"}, 200] & /@
 (Scaled /@ {.1, .3, .7, 1.}) // Row

enter image description here

Fixed font size versus varying image sizes:

plotnumber[options][3, {128, Red , FontFamily -> "SegoeScript"}, #] & /@ 
 {80, 100, 200, 250} // Row

enter image description here

Scaled font size versus varying image sizes:

plotnumber[options][3, {FontSize -> Scaled[1], Red , FontFamily ->"SegoeScript"}, #] & /@
 {80, 100, 200, 250} // Row

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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