Matlab画图设置线宽和字号

既然这么多人来这里看过,我就多做点注释,方便大家参考。

下边这段代码不需要特别设置,只需要在plot语句之后插入即可。

%plot your figure before

%%%%%%%%%%%%%%%%%%%%%

set(gcf,'Units','centimeters','Position',[10 10 7 5]);%设置图片大小为7cm×5cm
%get hanlde to current axis返回当前图形的当前坐标轴的句柄,
%(the first element is the relative distance of the axes to the left edge of the figure,...
%the second the vertical distance from the bottom, and then the width and height;
set(gca,'Position',[.13 .17 .80 .74]);%设置xy轴在图片中占的比例
set(get(gca,'XLabel'),'FontSize',8);%图上文字为8 point或小5号
set(get(gca,'YLabel'),'FontSize',8);
set(get(gca,'TITLE'),'FontSize',8);
set(gca,'fontsize',8);
set(gca,'linewidth',0.5); %坐标线粗0.5磅
set(gca,'box','off');%Controls the box around the plotting area
set(get(gca,'Children'),'linewidth',1.5);%设置图中线宽1.5磅

%%%%%%%%%%%%%%%%%%%%%%%%%%%%

下边附上其他参数的设置方法,其实就是利用函数句柄来对图形进行操作。有兴趣的自己研究研究:

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, ...

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

The axis system is defined in relative terms of the figure. That means that you don't tell Matlab to make the axis system 6 cm wide but say 0.6 times the width of the figure. To define the position (i.e., location with in the figure and size) you have to define 4 values: the horizontal location of the lower left corner of the plot area with respect to the lower left corner of the figure, the vertical position of the corner relative to the bottom of the figure, and the width and height of the axes system relative to the figure size. In the example above, I want the figure to start at 60% width and 20% height of the window. The size of the plot area shouls be 30% and 70% of the figure's width and height.
Here is an example where I am customizing the position option of the subplot function to create subplots without a gap between the axes systems.
Sometimes Matlab places the figure such that there is not enough space for the x and ylabels, especially when you use larger fontsizes. In such cases I move the axes around until everyting fits:

pos = get(gca,'position'); set(gca,'position',[0.15 pos(2) pos(3) pos(4)]);

First I copy the current position of the axes system into the vector pos (the first element is the relative distance of the axes to the left edge of the figure, the second the vertical distance from the bottom, and then the width and height). Assuming that you need more space for the ylabel, you want to shift the axes system to the left but keep the rest of the settings. The second statement does exactly that.

matlab 图像设置的更多相关文章

  1. matlab R2016b 设置界面为英文

    对于matlab的使用,最好还是使用英文好.这样既能让你熟悉直接的英文解释,也能学习一下英语. 对于中文版的matlab,默认的Matlab安装是中文,所以这里存在安装matlab后设置语言的需要. ...

  2. matlab图像类型转换以及uint8、double、im2double、im2uint8和mat2gray等说明

    转自:http://blog.csdn.net/fx677588/article/details/53301740 1. matlab图像保存说明 matlab中读取图片后保存的数据是uint8类型( ...

  3. Matlab图像彩色转灰色

    Matlab图像彩色转灰色 时间:2014年5月7日星期三 网上找的程序.实现图像彩色转灰色: I1=imread('C:\Users\Yano\Desktop\matlab\test1\4.jpg' ...

  4. matlab 图像和 opencv 图像的相互转换

    matlab可以生成C++代码, 但是在涉及图像数据的时候,要注意数据格式的转换. 1. Matlab图像数据在内存中的存放顺序是R通道图,G通道图,B通道图.对于每个通道,数据存放是先列后行. 2. ...

  5. matlab图像基础知识

    1.MATLAB支持的几种图像文件格式: ⑴JPEG(Joint Photogyaphic Expeyts Group):一种称为联合图像专家组的图像压缩格式. ⑵BMP(Windows Bitmap ...

  6. matlab图像灰度调整——imadjust函数的使用

    在MATLAB中,通过函数imadjust()进行图像灰度的调整,该函数调用格式如下: J=imadjust( I )  对图像I进行灰度调整 J=imadjust( I,[low_in;high_i ...

  7. 致敬学长!J20航模遥控器开源项目计划【开局篇】 | 先做一个开机界面 | MATLAB图像二值化 | Img2Lcd图片取模 | OLED显示图片

    我们的开源宗旨:自由 协调 开放 合作 共享 拥抱开源,丰富国内开源生态,开展多人运动,欢迎加入我们哈~ 和一群志同道合的人,做自己所热爱的事! 项目开源地址:https://github.com/C ...

  8. matlab 图像保存时去除白边

    很是讨厌MATLAB输出图像时自带的白边,尤其是当导出.eps格式时,很难通过编辑图片来去掉白边.网上有很多代码但是没有注释,有很多坑要填.这里提供一个去除白边的代码,自己在别人的基础上修改了而且加了 ...

  9. Matlab 图像预处理

    %%%%%%%%%%%%%%%%% %%降采样 clear all im={}; %创建字典保存读取的图片 dis=dir('F:\kaggle_data_zip\Sample\*.jpeg');%% ...

随机推荐

  1. LeetCode算法题-Find Pivot Index(Java实现)

    这是悦乐书的第304次更新,第323篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第172题(顺位题号是724).给定一个整数nums数组,编写一个返回此数组的" ...

  2. js斐波拉切

    如下: //1 1 2 3 5 8 13 21...//斐波拉切 function fei(n){ if(n==1 || n==2){ return 1 }else{ return fei(n-1)+ ...

  3. java-retry实现

    有这样一个需求,当调用某个方法抛出异常,比如通过 HttpClient 调用远程接口时由于网络原因报 TimeOut 异常:或者所请求的接口返回类似于“处理中”这样的信息,需要重复去查结果时,我们希望 ...

  4. Chinese Mahjong UVA - 11210 (暴力+回溯递归)

    思路:得到输入得到mj[]的各个牌的数量,还差最后一张牌.直接暴力枚举34张牌就可以了. 当假设得到最后一张牌,则得到了的牌看看是不是可以胡,如果可以胡的话,就假设正确.否者假设下一张牌. 关键还是如 ...

  5. 如何配置jenkins 与代理服务器吗?

    0       我们面临一些问题使用代理服务器(即缓存服务器)和詹金斯是希望有人可以提供如果他们有类似的设置.    Herea€™年代简要描述的设置: 在主站点反向代理,JTS & CCM服 ...

  6. Cordova入门系列(二)分析第一个helloworld项目 转发 https://www.cnblogs.com/lishuxue/p/6015420.html

    Cordova入门系列(二)分析第一个helloworld项目   版权声明:本文为博主原创文章,转载请注明出处 上一章我们介绍了如何创建一个cordova android项目,这章我们介绍一下创建的 ...

  7. Web 项目系列之浏览器机制(一)

    目录: ——初步认识浏览器 ——浏览器的渲染机制   ——浏览器的缓存机制 正文: 初步认识浏览器 想来任何一位读者,对浏览器都不会陌生.除开IT相关人员常用的Chrome(谷歌,Google).Fi ...

  8. 类String 初识

    String类概述 java.lang.String 类代表字符串.Java程序中所有的字符串文字(例如 "abc" )都可以被看作是实现此类的实例.类 String 中包括用于检 ...

  9. [kuangbin带你飞]专题二十二 区间DP----POJ - 2955

    区间DP标准入门题目. 区间DP大概思路是这样的. 第一层枚举长度,因为我们需要从小区间一步步推到大区间 第二层枚举左端点,那么右端点就定了. 第三层枚举间断点,由间断点合并得到大区间. 这道括号匹配 ...

  10. 使用队列实现栈(1)(Java)

    class MyStack { private Queue q1; private Queue q2; public MyStack(int size) { this.q1 = new Queue(s ...