Re: Text XY-size control in 2D graphics?
- To: mathgroup at smc.vnet.net
- Subject: [mg85144] Re: Text XY-size control in 2D graphics?
- From: "David Park" <djmpark at comcast.net>
- Date: Wed, 30 Jan 2008 06:05:47 -0500 (EST)
- References: <fnk3p2$l14$1@smc.vnet.net>
Gordon, There is something of a solution using the Presentations package. Needs["Presentations`Master`"] It is possible to do a number of transformations on regular 2D text including translations, rotations, shearings and scaling as long as the scaling is equal in both directions. Module[{txt = Text[Style["ATGC", 20, FontSize -> Scaled[.1]], {0, 0}]}, Draw2D[ {txt // RotateOp[\[Pi]/4], txt // ShearingTransformOp[-\[Pi]/8, {0, 1}, {1, 0}] // TranslateOp[{.5, 0}], txt // ScalingTransformOp[{2, 2}] // TranslateOp[{0, .5}]}, Frame -> True, PlotRange -> {{-1, 1}, {-.3, .7}}, ImageSize -> 300] ] But, as far as I can tell, it is not possible to use different scaling in the horizontal and vertical directions. I don't know whether this is an oversight or a built in limitation. In any case, Presentations has a capability called Text3D. This provides true 3D text that hides behind surfaces and rotates with the image and generally behaves like a 3D object. It can be plastered on surfaces and even warpped to fit on curved surfaces. Text3D provides independent specification of the width and height of the characters. Thus I found it quite easy to write a routine that converts Text3D to 2D text in the xy plane. Options[Text2D] = {Font3D -> FuturaFont3D, Align3D -> Center}; Text2D[s_, {xpos_, ypos_}, \[Theta]_, {hscale_, vscale_}, opts : OptionsPattern[]] := Normal[Text3D[ s, {xpos, ypos, 0}, {\[Theta], {0, 0, 1}}, {hscale, vscale}, opts]] /. {x_?NumberQ, y_?NumberQ, z_?NumberQ} -> {x, y} Then we can write 2D text with the xy scalings that you want. Text3D and now Text2D is not quite as nice as regular text. There are only two fonts, a Times font and a sans serif Futura font. It is not possible to use the text within Text or Style statements. But it is quite adequate for the purpose. Here is an example that scales the letters 2 to 1 and 4 to 1 in the y direction. Draw2D[ {AbsoluteThickness[2], Blue, Text2D["AGCT", {0, 0}, 0 =B0, .2 {1, 4}, Font3D -> TimesFont3D, Align3D -> Right], AbsoluteThickness[4], Red, Text2D["AGCT", {0, 0}, 0 =B0, .2 {1, 2}, Font3D -> FuturaFont3D, Align3D -> Left]}, Frame -> True, PlotRange -> 2, ImageSize -> 300] -- David Park djmpark at comcast.net http://home.comcast.net/~djmpark/ "Gordon Robertson" <agrobertson at telus.net> wrote in message news:fnk3p2$l14$1 at smc.vnet.net... >I would like to generate sequence logos (http://weblogo.berkeley.edu/ > examples.html) using v6's 2D graphics 'Text'. > > Below is an early and unsuccessful attempt to build a single column > of stacked ACGT characters. Clearly I don't understand how to > position letters correctly, using settings for text size, position > and offset, and image size... but I imagine that it's possible to do > this. What's currently a bigger concern is that I need to control the > height of a character while keeping its width fixed, but for sizing > letters I see only FontSize[param]. I've checked the online > documentation, Options[Text], 'Mma Navigator', and Google, without > finding how to do this. > > Can anyone help by showing how to control Text character width and > height independently? > > ff = "Helvetica"; > Show[ > Graphics[ > Text[Style["A", Green, Bold, FontSize -> Scaled[0.5], FontFamily - > > ff], {1, > 0}, {0, -1}]], > Graphics[ > Text[Style["C", Blue, Bold, FontSize -> Scaled[0.3], FontFamily -> > ff], {1, > 0}, {0, -3}]], > Graphics[ > Text[Style["G", RGBColor[1, 0.7, 0], Bold, FontSize -> Scaled[0.15], > FontFamily -> ff], {1, 0}, {0, -4.5}]], > Graphics[ > Text[Style["T", Red, Bold, FontSize -> Scaled[0.05], FontFamily -> > ff], {1, > 0}, {0, -7}]], > Frame -> True, FrameLabel -> {None, "bits"}, FrameTicks -> {{{0.5, > 1, 1.5, 2}, None}, {{1}, None}}, > PlotRange -> {{0.5, 1.5}, {0, 2}}, AspectRatio -> 1, ImageSize -> 200 > ] > > G > -- > Gordon Robertson > Canada's Michael Smith Genome Sciences Centre > Vancouver BC Canada > >