这一篇是关于画图美化的第二篇
这一节我们讲一下
1.Exclusions 有奇点时的处理办法
2.Axes,AxesLabel,AxesStyle 对坐标轴的处理
3.Frame,FrameTicks,FrameStyle对边框的处理
首先来看关于奇点的处理
Plot[Tan[x], {x, -2 Pi, 2 Pi}]
像这样画出来的图是这样的
很明显,在奇点的地方多了一竖
那么,我们要把它去掉
Plot[Tan[x], {x, -2 Pi, 2 Pi}, Exclusions -> Cos[x] == 0,ExclusionsStyle -> Dashed]
(*排除Cos[x]\[Equal]0的点*)
的到下面的图
这样就和正确的图是一样的了
我们再举一个例子
GraphicsRow[{
Plot[1/((x - 1)*(x - 2)), {x, 0, 3}, ImageSize -> Medium],
Plot[1/((x - 1)*(x - 2)), {x, 0, 3}, Exclusions -> {x == 1, x == 2},
ImageSize -> Medium]
}]
得到下面的图
下面看一下对于坐标轴的处理
GraphicsRow[{
Plot[Sin[x], {x, 0, 2 Pi}, ImageSize -> Small],
Plot[Sin[x], {x, 0, 2 Pi}, Axes -> False, ImageSize -> Small],
Plot[Sin[x], {x, 0, 2 Pi}, Axes -> {True, False},
ImageSize -> Small],
Plot[Sin[x], {x, 0, 2 Pi}, Axes -> {False, True}, ImageSize -> Small]
}]
可以看到,是对坐标轴出现的表示
下面看一下如何对x,y轴标标签
GraphicsRow[{
Plot[Sin[x], {x, 0, 2 Pi},
AxesStyle -> Lighter[Gray],
ImageSize -> 300,
AxesLabel -> {Style[x, 20], Style[y, 20]}],
Plot[
Sin[x], {x, 0, 2 Pi},
AxesStyle -> Lighter[Gray],
ImageSize -> 300,
AxesLabel -> {Style[TraditionalForm@Sin[x], Italic, 24], None}]
}]
的到下面的图
是不是比一开始的时候好看了很多
下面讲给图形加上边框
GraphicsRow[{
Plot[Tan[x], {x, -3 Pi, 3 Pi}, Exclusions -> Cos[x] == 0,
Frame -> True, Axes -> {True, True}],
Plot[Tan[x], {x, -3 Pi, 3 Pi}, Exclusions -> Cos[x] == 0,
ExclusionsStyle -> Dashed, Axes -> False]
},
ImageSize -> 1200
]
的到下面的图
对于边框的修改规则是这样的 Frame->{{left,right},{bottom,top}}
(*Frame\[Rule]{{Left,Right},{Bottom,Top}}牢记这条语法,还有很多是这样的*)
Plot[
Tan[x], {x, -3 Pi, 3 Pi},
Exclusions -> Cos[x] == 0,
ExclusionsStyle -> Dashed,
ImageSize -> 500,
PlotLabel -> Style[左下边框, Bold, 24],
Frame -> {{True, False}, {True, False}},
AxesLabel -> {Style[TraditionalForm@Tan[x], 24], None}
]
的到下面的图
下面讲一下如何控制边框的刻度
(* FrameTicks 来控制刻度,他的顺序也是 \
FrameTicks\[Rule]{{Left,Right},{Bottom,Top}}*)
tick = Table[i, {i, -7, 7, 0.5}];
(*这样可以指定坐标轴的间隔*)
Plot[
Tan[x], {x, -3 Pi, 3 Pi},
Exclusions -> Cos[x] == 0,
ExclusionsStyle -> Dashed,
ImageSize -> 900,
Frame -> True,
FrameTicks -> {{tick, None}, {Automatic, None}},
FrameTicksStyle -> {{Green, Blue}, {Directive[Red, 24], Black}}
(*可以控制字体的大小*)
]
的到下面的图
下面看一个稍微复杂一点的,使得标签外凸
Plot[
Sin[x], {x, -2 Pi, 2 Pi},
ImageSize -> 500,
Frame -> True,
FrameTicks -> {
{{-1, 0, {1, 1, {0.1, 0.02}, Directive[Thick, Red]}}, Automatic},
{Automatic, Automatic}
}
]
得到下面的图
最后看一个综合一点的例子
Plot[
Sin[x], {x, 0, 2 Pi},
AxesStyle -> {Directive[Orange, 12], Blue},
Ticks -> {
Table[{d Degree, d Degree, {0.02, 0.01}}, {d, 0, 360, 90}],
Automatic
}
]
的到下面的图
上面我大概讲了一下关于坐标,和边框的处理
关于美化 明天还会有一篇
2016/8/15
以上,所有