MATLAB study notes (b) drawing

Note catalog, content, screenshots and video courseware from B station Guo Yanfu teacher

Basic plotting

一:Plot from Data

plot( )

  1. plot(x,y)

  2. plot (y) [or Plot (x)]: the value of x at this time is taken 1: n. The plot (cos (0: pi / 20: 2 * pi))

  3. If you want to draw two graphs in a chart on the increase: hold on and hold off
    such as:
    Here Insert Picture Description
    Here Insert Picture Description

Two: Plot style

plot(x,y,‘str’)

Str where we want to change elements
Here Insert Picture Description
such as: use hold can make a figure in several views in
Here Insert Picture Description
Here Insert Picture Description

legend()

legend(‘L1’,‘L2’,…)
Here Insert Picture Description
Here Insert Picture Description

title( ) and ?label( )

  1. title()
    xlabel()
    ylabel()
    zlabel()

  2. Figure chestnutsHere Insert Picture Description
    Here Insert Picture Description

text() and annotation()

LaTax: annotate
Here Insert Picture Description

linspace (x0, x1, n)
where n represents the number of points, i.e., n-1 is divided into aliquots.
Step should be (x1-x0) / (n -1)

练习:
Here Insert Picture Description
t=linspace(1,2);
f=t.^2;
g=sin(2*pi.*t);
plot(t,f,‘k-’,t,g,‘ro’);
legend(‘t^2’,‘sin(2\pi{t})’);
xlabel(‘Time(ms)’);
ylabel(‘f(t)’);
title(‘Mine assignment’);

Graphical object properties

Here Insert Picture Description

  • figure object
  • axes object
  • line object
  • Here Insert Picture Description

一:修改项目

Here Insert Picture Description

先找到需要修改的地方,再去改

寻找到需要修改的地方

Here Insert Picture Description

提取或者设置图像性质

  • get()
  • set()

栗子:(修改数据)
x=linspace(0,2*pi,1000);
y=sin(x);
h=plot(x,y);
get(h)

Here Insert Picture Description
得到了:
AlignVertexCenters: ‘off’
Annotation: [1×1 matlab.graphics.eventdata.Annotation]
BeingDeleted: ‘off’
BusyAction: ‘queue’
ButtonDownFcn: ‘’
Children: [0×0 GraphicsPlaceholder]
Clipping: ‘on’
Color: [0 0.4470 0.7410]
CreateFcn: ‘’
DeleteFcn: ‘’
DisplayName: ‘’
HandleVisibility: ‘on’
HitTest: ‘on’
Interruptible: ‘on’
LineJoin: ‘round’
LineStyle: ‘-’
LineWidth: 0.5000
Marker: ‘none’
MarkerEdgeColor: ‘auto’
MarkerFaceColor: ‘none’
MarkerIndices: [1×1000 uint64]
MarkerSize: 6
Parent: [1×1 Axes]
PickableParts: ‘visible’
Selected: ‘off’
SelectionHighlight: ‘on’
Tag: ‘’
Type: ‘line’
UIContextMenu: [0×0 GraphicsPlaceholder]
UserData: []
Visible: ‘on’
XData: [1×1000 double]
XDataMode: ‘manual’
XDataSource: ‘’
YData: [1×1000 double]
YDataSource: ‘’
ZData: [1×0 double]
ZDataSource: ‘’

get(h)是得到的line数据
get(gca)的得到axes坐标轴的数据

set(gca,‘XLim’,[0,2*pi]);
set(gca,‘YLim’,[-1.2,1.2]);

做完以上操作之后得到的图形:
Here Insert Picture Description

还有一种做法:xlim([0,2*pi]) ;ylim([-1.2,1.2])

若是想修改坐标轴axes和背景参数figure等的性质(字体、符号等)

fontsize:改变坐标轴数字的字体大小
Here Insert Picture Description
!此处symbol没有正常运行

若是改变line
Here Insert Picture Description

Marker Specification

Here Insert Picture Description
练习
Here Insert Picture Description
t=linspace(1,2);
f=t.^2;
g=sin(2*pi.*t);
hold on
h=plot(t,f,‘k-’);
m=plot(t,g,‘ro’);
hold off
legend(‘t^2’,‘sin(2\pi{t})’);
xlabel(‘Time(ms)’);
ylabel(‘f(t)’);
title(‘Mine assignment’);
set(gca,‘FontSize’,17);
set(h,‘linewidth’,5.0);
set(m,‘color’,‘r’,‘markerfacecolor’,‘b’);

二:Multiple Figures(画很多个图)

多个窗口展现
figure,plot(x,y1);
figure,plot(x,y2);

注意:此时的gcf,gca都是只的figure2

还可以改变figure窗口的长宽,位置
figure(’Position’,[left,bottom,width,height]);

多个图画在一个figure里
subplot(m,n,x);

m是row,n是column,x的取值范围在1到m*n
Here Insert Picture Description

举个例子
Here Insert Picture Description

equal:x,y轴的刻度是一样的
square:将当前坐标系图形设置为方形。横轴及纵轴比例是1:1
equal tight:
axis tight:数据范围设为坐标范围

Other instructions about axes
Here Insert Picture Description

axis on / off: turn on or off axis, only graphic
grid: the grid line coordinate axis in the
box: the axis above the blank

Save graphics

saveas(gcf,‘filename’,‘formattype’);

formattype: Specifies the storage format
Here Insert Picture Description
if you want high resolution, with print

Advanced Plotting

Advanced 2D plots

Color space

3D plots

Released six original articles · won praise 0 · Views 211

Guess you like

Origin blog.csdn.net/qq_45793719/article/details/104250250