a=linspace( 1,2,10)
plot(a,'--pr','linewidth',1.5,'MarkerEdgeColor','r','MarkerFaceColor','m','MarkerSize',10)
legend ( 'a','Location','best')
title ( 'a','FontName','Times New Roman','FontWeight','Bold','FontSize', 16)
xlabel ( 'T','FontName','Times New Roman','FontSize', 14)
ylabel ( 'a','FontName','Times New Roman','FontSize', 14,'Rotation', 0)
axis auto equal
set ( gca,'FontName','Times New Roman','FontSize', 14)
1.曲线线型、颜色和标记点类型
plot(X1,Y1,LineSpec, …) 通过字符串LineSpec指定曲线的线型、颜色及数据点的标记类型。
- 实线 r 红色 + 加号
-. 点划线 g 绿色 o 圆圈
-- 虚线 b 蓝色 *星号
: 点线 c 蓝绿色 . 点
m 洋红色 x 交叉符号
y 黄色 square(或s) 方格
k 黑色 diamond(或d) 菱形
w 白色 ^向上的三角形
v向下的三角形 >向左的三角形
<向右的三角形 pentagram(或p) 五边形
hexagram(或h) 六边形
线的颜色是由红绿蓝(RGB)三原色组成的,通过设定三原色的权重可以改变线的颜色,命令如下(x为横坐标,y为纵坐标):
color的域值为0—1
当需要以上常用的八种以外的颜色时,只要设置颜色中RGB的值就可以得到不同的颜色。
2.设置曲线线宽、标记点大小,标记点边框颜色和标记点填充颜色等。
Property Name 意义 选项
LineWidth 线宽 数值,如0.5,1等,单位为points
MarkerEdgeColor 标记点边框线条颜色 颜色字符,如’g’, ’b’等
MarkerFaceColor 标记点内部区域填充颜色 颜色字符
MarkerSize 标记点大小 数值,单位为points
例: 设置图线的线形、颜色、宽度、标记点的颜色及大小。
t=0: pi/20: pi; y=sin( 4*t). *sin( t) /2;
plot(t,y,'-bs','LineWidth',2,'MarkerEdgeColor','k', 'MarkerFaceColor', 'y','MarkerSize',10);
3.坐标轴设置
范围设置:
a. axis([xmin xmax ymin ymax])设置坐标轴在指定的区间
b.
c.
d.
比例:
a.
b.
c.
范围选项和比例设置可以联合使用
axis ij :设置坐标轴的原点在左上角,i为纵坐标,j为横坐标
4.坐标轴刻度设置
‘FontWeight’,’bold’ 加粗 ‘FontAngle’,’italic’ 斜体
对字体的设置也可以用在title, xlabel, ylabel等中
5.图例
这些是Matlab help文件。后面一段是对应的翻译和说明
'North' inside plot box near top
'South' inside bottom
'East' inside right
'West' inside left
'NorthEast ' inside top right (default)
'NorthWest inside top left
'SouthEast ' inside bottom right
'SouthWest ' inside bottom left
'NorthOutside ' outside plot box near top
'SouthOutside ' outside bottom
'EastOutside ' outside right
'WestOutside ' outside left
'NorthEastOutside ' outside top right
'NorthWestOutside ' outside top left
'SouthEastOutside ' outside bottom right
'SouthWestOutside ' outside bottom left
'Best' least conflict with data in plot
'BestOutside ' least unused space outside plot
'North' 图例标识放在图顶端
'South' 图例标识放在图底端
'East' 图例标识放在图右方
'West' 图例标识放在图左方
'NorthEast ' 图例标识放在图右上方( 默认)
'NorthWest 图例标识放在图左上方
'SouthEast ' 图例标识放在图右下角
'SouthWest ' 图例标识放在图左下角
(以上几个都是将图例标识放在框图内)
'NorthOutside ' 图例标识放在图框外侧上方
'SouthOutside ' 图例标识放在图框外侧下方
'EastOutside ' 图例标识放在图框外侧右方
'WestOutside ' 图例标识放在图框外侧左方
'NorthEastOutside ' 图例标识放在图框外侧右上方
'NorthWestOutside ' 图例标识放在图框外侧左上方
'SouthEastOutside ' 图例标识放在图框外侧右下方
'SouthWestOutside ' 图例标识放在图框外侧左下方
(以上几个将图例标识放在框图外)
'Best' 图标标识放在图框内不与图冲突的最佳位置
'BestOutside ' 图标标识放在图框外使用最小空间的最佳位置
还是用上面的例子
legend ( 'sin','cos','location','northwest')
可以将标识框放置在图的左上角Examples:
x = 0:. 2:12;
plot(x,bessel(1,x),x,bessel(2,x),x,bessel(3,x));
legend ( 'First','Second','Third');
legend ( 'First','Second','Third','Location','NorthEastOutside')
b = bar( rand ( 10,5),'stacked'); colormap( summer); hold on
x =
plot( 1:10,5*rand( 10,1),'marker','square','markersize ', 12,'markeredgecolor ','y','markerfacecolor ', [. 6
0 . 6],'linestyle ','-','color','r ','linewidth ', 2); hold off
legend ( [b, x],'Carrots','Peas','Peppers','Green Beans','Cucumbers','Eggplant')
6.图形窗口
(1
figure(n):用于为当前的绘图创建图形窗口,每运行一次figure就会创建一个新的图形窗口,n表示第n个窗口,如果窗口定义了句柄,也可以用figure(h)将句柄h的窗口作为当前窗口。
(2
subplot(m,n,p):把窗口分成m×n个小窗口,并把第p个窗口当作当前窗口。
例:将4 个图形显示在同一个图形窗口中。
t=0: pi/20:2*pi; [x, y] =meshgrid( t);
subplot ( 2,2,1); plot( sin( t), cos( t)); axis equal
subplot ( 2,2,2); z=sin( x) +cos( y); plot( t, z); axis( [0 2*pi –2 2])
subplot ( 2,2,3); z=sin( x). *cos( y); plot( t, z); axis( [0 2*pi –1 1])
subplot ( 2,2,4); z=sin( x). ^2-cos( y). ^2; plot( t, z); axis( [0 2*pi –1 1])
(3
例:将peaks函数的等高线图与伪彩色画在一起。
[x,y,z]=peaks; %产生双变量数组
contour(x,y,z,20,'k') %绘制等高线
hold on
pcolor(x,y,z) %绘制伪彩色图
shading interp %表面色彩渲染
hold off
7
加注坐标轴标识
图形标题: title
例:加注坐标轴标示和图形标题。
t=0: pi/100:2*pi;y=sin( t);
plot ( t, y)
axis ( [0 2*pi,-1 1])
xlabel('0 \leq \itt \rm \leq \pi','FontSize',16)
ylabel ( 'sin( t)','FontSize', 20)
title('正弦函数图形','FontName','隶书','FontSize',20)
8. 图中加注文本
例:在上图中加语句。
t=0: pi/100:2*pi;
y=sin( t);
plot ( t, y)
axis ( [0 2*pi,-1 1])
xlabel('0 \leq \itt \rm \leq \pi','FontSize',16)
ylabel ( 'sin( t)','FontSize', 20)
title('正弦函数图形','FontName','隶书','FontSize',20)
text(3*pi/4,sin(3*pi/4),'\leftarrowsin(t)=0.707', 'FontSize',16)
text(pi,sin(pi),'\leftarrowsin(t)=0', 'FontSize',16)
text(5*pi/4,sin(5*pi/4),'sin(t)=-0.707\rightarrow','FontSize',16,'HorizontalAlignment','right')
句中:
gtext('字符串'): 在图形窗口上用鼠标直接在指定的位置上加注文本。
例:
t=0: pi/100:2*pi;
y=sin( t);
plot ( t, y)
axis ( [0 2*pi,-1 1])
xlabel('0 \leq \itt \rm \leq \pi','FontSize',16)
ylabel ( 'sin( t)','FontSize', 20)
title('正弦函数图形','FontName','隶书','FontSize',20)
gtext ( 'MATLAB')
9. 指定TeX字符
例:在标题中指定TeX字符
t=0: pi/100:2*pi;
alpha=-0.8;
beta=15;
y=sin( beta*t). *exp( alpha*t);
plot ( t, y)
title('{\itAe}^{-\it\alpha\itt}sin\it\beta{\itt}\it\alpha<<\it\beta')
xlabel('时间\mus.'),
ylabel('幅值')
在title中的字符串表现的是 Aeαt sinβt α<<β
斜体Ae 上标斜体αt 斜体βt 斜体α 斜体β
希腊字母 MatLab表示
α \alpha
β \beta
γ \gamma
θ \theta
Θ \Theta
Г \Gamma
δ \delta
Δ \Delta
ξ \xi
Ξ \Xi
η \elta
ε \epsilong
ζ \zeta
μ \miu
υ \nu
τ \tau
λ \lamda
Λ \Lamda
π \pi
Π \Pi
σ \sigma
Σ \Sigma
φ \phi
Φ \Phi
ψ \psi
Ψ \Psi
χ \chi
ω \ommiga
Ω \Ommiga
\geq
不等于 \neq
<> \gg
正负 \pm
左箭头 \leftarrow
右箭头 \rightarrow
上箭头 \uparrow
上圆圈( 度数) \circ
摄氏度 \circC
10 hold on/off用后导致plot后最右侧和最上侧边框消失的问题
hold on后继续写box on
在xlabel或者ylabel上使用LaTex的表示方法,如
xlabel('$\alpha$','Interpreter','LaTex')
在legend中使用LaTex的表示方法,如
h = legend('$k_{rw} 90 ^\circ C$');
Comments
Post a Comment