matlab 图层,matlab绘图进阶(翻译总结)

Here are some tips on making "better" figures with Matlab for

theses, papers/abstracts, and reports. Basically, you need to

change/disable some of Matlab's default settings to get the print

you want.

Figures and axes/subplots are defined in Matlab by a set of

"handles" that, for example, define the size of a figure or the

position of an axes system within a figure. To

understand how this work you must know that Matlab is written

object oriented. The way I understand is that there is a hierachie

in the different objects. For example, your screen has the highest

priority as it defines the maximum size a (usable) figure can have.

The next lower member is the figure. If you change a figure size,

the screen won't be affected, but if you could shrink the screen

size, the figure size would be changed as well. Next comes the axes

system(s) in the figure. The size and position of the axes system

depends on the figure. For example, if you shrink the size of the

figure, the size of your plot will change accordingly. On the other

hand, if you change the size of a subplot/axes, the figure will not

change. The object oriented guys call this parents (higher ranking

in the hierachy) and children thing.

In Germany, we have the saying that trying is more worth and

studying or practise makes the master. Therefore, I recommend that

you play with these options to see how they change the appearence

of your figure plot, ...

Getting handels/setting properties:

I'll start first with a list ofparameters that you can use to

modify a matlab plot and then go intomore details later. Start with

the following commands to create a lineplot:

figure

h=plot(randn(100,1));

Then type one after the other:

get(gcf)

get(gca)

get(h)

What you will see in the command window is a list of handles

thatallows you modify you plots. A list of the most important (aka

the onesI am using the most frequently) is this one here:

Figures

color:

Allows you to change the color of the figure (the area around the

axes system). You can do it by the following

command:

set(gcf,'color',[0 0 0.3]);

This will create a dark blue

color.

Colors in Matlab are handled as red-green-blue tribles where each

valuevaries between 0 and 1. For example, red is [1 0 0], green [0

1 0],yellow [1 1 0], white [1 1 1], and black [0 0 0]. Grays are [x

x x]with 0 < x < 1.

This setting makes only sense if you also set the

parameter

Inverthardcopy

off.

In this case, Matlab will not change the figure color to white when

you print the figure or save it to a graphics

format:

set(gcf,'inverthardcopy','off');

PaperPositionMode

Per default, Matlab resizes a figure when printing or saving it to

agraphics file. To disable this resizing, set the PaperPositionMode

toauto (default is manual):

set(gcf,'paperpositionmode','auto');

The function cfigure does it automatically. After setting

thisparameter and printing the figure it should have the same size

andaspect ratio as it appears on the screen.

Position

Allows you to define the size of a figure. See below for more

details.

Axes

box

Controls the box around the plotting area. To have a line all

around the plotting area, use

set(gca,'box','on');

color

Defines the color of the plotting area (the axes are controlled

separately):

set(gca,'color',[1 1 1]*0.9);

sets the color to a light gray.

xcolor, ycolor, zcolor

Use these parameters to change the color of the axes and the

associated ticklabels:

set(gca,'color',[1 1

1]*0.8,'xcolor','r','ycolor','b');

(this color choice is only to illustrate the potential but not a

recommendation for a serious presentation)

Fontsize

Controls the fontsize of the axes tick labels (NOT the xlabel,

ylabel, and title).

set(gca,'fontsize',18);

Fontweight

Change the fontstyle to bold or back to

normal:

set(gca,'fontweight','bold');

set(gca,'fontweight','normal');

Again, the axes labels are not affected.

Layer

Some pseudo color plots like imagesc or pcolor cover the ticks of

theaxes (and gridlines, if applicaple). To bring them up again,

use

set(gca,'layer','top');

Linewidth

To increase the width of an axes or grid

line:

set(gca,'linewidth',3);

Note: the width of a plot line will not

change

position

To place a the plotting area within the figure. See below

...

xdir, ydir, zdir

Can be reverse or normal:

set(gca,'ydir','reverse');

xscale,yscale

Can be lin (linear) or log

(logarithmic)

set(gca,'xscale','log')

xaxislocation

Can be top or bottom. In certain seismic plots it looks good to

havethe xaxis at the top and the vertical (y-) axis increasing

downwards:

set(gca,'xaxislocation','top','ydir','reverse')

yaxislocation

Can be left or right.

Plot

Color

To change the color of the line. Default is blue, so if yoiu want

to change that after plotting do the

following:

set(h,'color',[0.2 0.9 0.314]);

Linestyle

To modify the line style. Possible options are ':' dotted, '-'

solid, '--' dashed, '-.'

dash-dotted

set(h,'linestyle',':');

Linewidth

To increase the linewidth: set(h,'linewidth',10)

Marker

To change/add a marker to the plotted data, for

example

set(h,'marker','o')

to add a circle at every data point.

Markersize

You can increase the size of the marker

by

set(h,'markersize',8)

Markeredgecolor

The color of the marker can be

different:

set(h,'markeredgecolor','w'),

and separately you can set the

markerfacecolor

such that

set(h,'marker','d','markeredgecolor','r','markerfacecolor','g');

Of course you can combine the settings into a single

command:

set(gca,'xaxislocation','top','ydir','

reverse','inverthardcopy','off')

set(h,'linewidth',5,'marker','v','mark

erfacecolor','k','markeredgecolor','r').

In case of the plotting command, you can also include these

settings in the plot

instructions:

plot(xdata,ydata,'-og','linewidth',3,'

markerfacecolor','r','markeredgecolor','y')

For xlabel, ylabel and title it is actually easier to set the

layout when making the labels, for example

xlabel('text','fontsize',14,... 'fontweight','bold',... 'color','m')

Or

you can get a list of options by first creating the xlabel, and

then

get(get(gca,'xlabel'))

Then

setting parameters (e.g., fontsize) goes like that

set(get(gca,'xlabel'),'fontsize',10)

On the position options

Position and size of figures and axes systems are handled object

oriented in Matlab. That basically means that the size of a figure

window is defined in relative terms of the size of the next higher

order member in the hierachy, which is the screen size. Similarly,

the size of an axes system is defined in terms of the figure size.

Take a look at the following sketch

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值