星期二, 八月 29, 2006

Cool Tips:Mathematica Notebook 输出文本控制

Mathematica里的文本输出是Print方法。
在Mathematica里,文本的被抽象为text和Form.
标准的对象构造方法为:Text.
Show[Graphics[Text["hi",{10,10}]]]


可以控制字体各种属性的构造方法为: StyleForm
StyleForm["2005 Year",
FontSize -> 24, FontWeight -> "Bold", FontColor ->
RGBColor[1, 0, 0],Background->GrayLevel]];

输出大字:2005 Year

StyleForm是最常用的用来控制艺术文字输出的。
但有时侯需要输出格式化的数学公式之类的,就需要用其他的Form
StyleForm的标准构造如下。
StyleForm[expr, options]
其中expr可以接受表达式的输入。
比如输出一个数学公式,需要用M的函数StandForm来格式化。
values=BesselJ[5,Range[20]];
ListPlot[values, PlotLabel -> StyleForm[
StandardForm[1/x^2],
FontSize -> 24, FontWeight -> "Bold", FontColor -> RGBColor[
1, 0, 0], Background -> GrayLevel[0.5]]]
得到如图:


Graphics有两个Hook方法.Prolog和Epilog分别是在绘画主图前和后调用来产生图形同主图形
透视的函数。
比如想在一个圆点内写上字,就应该如下:
Show[Graphics[{{PointSize[.075], RGBColor[1, 0, 0], Point[{0, 0}]}}], Epilog -> Text["1", {0, 0}, TextStyle -> {FontSize -> 24, FontStyle -> "BOLD", FontColor -> RGBColor[0, 1, 0]}]];