先前讲解了简单绘图方法: http://www.cnblogs.com/youxin/p/3859923.html
x = 0:pi/100:2*pi;
y = sin(x);
plot(x,y)
下面例子:

This example shows how to create a simple line graph. Use the linspace function to define x as a vector of 100 linearly spaced values between 0 and .
x = linspace(0,2*pi,100);

Define y as the sine function evaluated at the values in x.
y = sin(x);

Plot y versus the corresponding values in x.
figure
plot(x,y)

Create Graph in New Figure Window

This example shows how to create a graph in a new figure window, instead of plotting into the current figure.

Define x and y.
x = linspace(0,2*pi,25);
y = sin(x);

Create a stairstep plot of y versus x. Open a new figure window using the figure command. If you do not open a new figure window, then by default, MATLAB® clears existing graphs and plots into the current figure.
figure % new figure window
stairs(x,y)

Plot Multiple Lines

This example shows how to plot more than one line by passing multiple x,y pairs to the plot function.

Define y1 and y2 as sine waves with a phase shift.

x = linspace(0,2*pi,100);
y1 = sin(x);
y2 = sin(x-pi/4);

Plot the lines.

figure
plot(x,y1,x,y2)

plot cycles through a predefined list of line colors.

Colors, Line Styles, and Markers

To change the line color, line style, and marker type, add a line specification string to the x,y pair. For example, adding the string, 'g:*', plots a green dotted line with star markers. You can omit one or more options from the line specification, such as 'g:' for a green dotted line with no markers. To change just the line style, specify only a line style option, such as '--' for a dashed line.

For more information, see LineSpec (Line Specification).

Specify Line Style

This example shows how to create a plot using a dashed line. Add the optional line specification string, '--', to the x,y pair.

x = linspace(0,2*pi,100);
y = sin(x); figure
plot(x,y,'--')

Specify Different Line Styles for Multiple Lines

This example shows how to plot two sine waves with different line styles by adding a line specification string to each x,y pair.

Plot the first sine wave with a dashed line using '--'. Plot the second sine wave with a dotted line using ':'.

x = linspace(0,2*pi,100);
y1 = sin(x);
y2 = sin(x-pi/4); figure
plot(x,y1,'--',x,y2,':')

Specify Line Style and Color

This example shows how to specify the line styles and line colors for a plot.

Plot a sine wave with a green dashed line using '--g'. Plot a second sine wave with a red dotted line using':r'. The elements of the line specification strings can appear in any order. 元素可以无序出现。

x = linspace(0,2*pi,100);
y1 = sin(x);
y2 = sin(x-pi/4); figure
plot(x,y1,'--g',x,y2,':r') g--也行。

Specify Line Style, Color, and Markers

This example shows how to specify the line style, color, and markers for two sine waves. If you specify a marker type, then plot adds a marker to each data point.

Define x as 25 linearly spaced values between 0 and  . Plot the first sine wave with a green dashed line and circle markers using '--go'. Plot the second sine wave with a red dotted line and star markers using':r*'.

x = linspace(0,2*pi,25);
y1 = sin(x);
y2 = sin(x-pi/4); figure
plot(x,y1,'--go',x,y2,':r*')

Plot Only Data Points

This example shows how to plot only the data points by omitting the line style option from the line specification string.

Define the data x and y. Plot the data and display a star marker at each data point.

x = linspace(0,2*pi,25);
y = sin(x); figure
plot(x,y,'*')

----------------------------------------------------------------------

Create Simple Line Plot

Define x as 100 linearly spaced values between  and  . Define y1 and y2 as sine and cosine values ofx. Create a line plot of both sets of data.

x = linspace(-2*pi,2*pi,100);
y1 = sin(x);
y2 = cos(x); figure
plot(x,y1,x,y2)

Add Title

Add a title to the graph using the title function. Pass the title function a text string with the desired title.

To display Greek symbols in a title, use the TeX markup. Use the TeX markup, \pi, to display the Greek symbol  .

title('Graph of Sine and Cosine Between -2\pi and 2\pi')

Add Axis Labels

Add axis labels to the graph using the xlabel and ylabel functions. Pass these functions a text string with the desired label.

xlabel('-2\pi < x < 2\pi') % x-axis label
ylabel('sine and cosine values') % y-axis label

Add Legend

Add a legend to the graph identifying each data set using the legend function. Pass the legend function a text string description for each line. Specify legend descriptions in the order that you plot the lines.

指定lengend根据你画线的顺序。

legend('y = sin(x)','y = cos(x)')

Change Legend Location

Change the location of the legend on the graph by setting its location using one of the eight cardinal or intercardinal directions. Display the legend at the bottom left corner of the axes by specifying its location as'southwest'.

To display the legend outside the axes, append outside to any of the directions, for example,'southwestoutside'.

legend('y = sin(x)','y = cos(x)','Location','southwest')

Change Axis Limits of Graph

This example shows how to change the axis limits of a graph. By default, MATLAB® chooses axis limits to encompass the data plotted.

encompass:包围,环绕。

Create Simple Line Plot

Define x as 200 linearly spaced values between -10 and 10. Define y as the sine of x with an exponentially decreasing amplitude. Create a line plot of the data.

x = linspace(-10,10,200);
y = sin(4*x)./exp(x); figure
plot(x,y)

Change Axis Limits

Change the axis limits by passing to the axis function a four-element vector of the form[xmin,xmax,ymin,ymax], where xmin and xmax set the scaling for the x-axis, and ymin and ymax set the scaling for the y-axis.

You also can change the axis limits using the xlimylim, and zlim functions. The commandsxlim([xmin,xmax]) and ylim([ymin,ymax]) produce the same result as axis([xmin,xmax,ymin,ymax]).

Change the x-axis scaling to range from 0 to 10. Change the y-axis scaling to range from -1 to 1.

axis([0,10,-1,1])

Use Semiautomatic Axis Limits

Use an automatically calculated minimum x-axis limit by settings its value to -inf. MATLAB® calculates the limit based on the data. Specify values for the maximum x-axis limit and the y-axis limits.

axis([-inf,10,-1,1])

To use an automatically calculated maximum limit, set the value to inf.

-------------

Change Tick Marks and Tick Labels of Graph

This example shows how to change the tick marks and the tick mark labels. MATLAB® chooses tick mark locations based on the range of the data and automatically uses numeric labels at each tick mark.

reate Simple Line Chart

Define x as 200 linearly spaced values between -10 and 10. Define y as the cosine of x. Plot the data.

x = linspace(-10,10,200);
y = cos(x); figure
plot(x,y)

Change Tick Marks

Change the location of the tick marks on the plot by setting the XTick and YTick properties of the axes. Usegca to set the properties for the current axes. Define the tick marks as a vector of increasing values. The values do not need to be equally spaced.

set(gca,'XTick',[-3*pi,-2*pi,-pi,0,pi,2*pi,3*pi])
set(gca,'YTick',[-1,-0.5,0,0.5,1]) 改变横坐标和纵坐标的tick mark。

Change Tick Mark Labels

Specify tick mark labels by setting the XTickLabel and YTickLabel properties of the axes. Set these properties using a cell array of strings with the desired labels. If you do not specify enough text labels for all the tick marks, then MATLAB cycles through the labels.

set(gca,'XTickLabel',{'-3pi','-2pi','-pi','0','pi','2pi','3pi'})
set(gca,'YTickLabel',{'min = -1','-0.5','0','0.5','max = 1'})

----------------------------------------------------

Create Figure With Multiple Graphs Using Subplots

This example shows how to create a figure containing multiple graphs using the subplot function. The syntax, subplot(m,n,p), divides the figure into an m-by-n grid with an axes in the pth grid location. The grids are numbered along each row.

Create Subplots and Add Subplot Titles

Use subplot to create a figure containing a 2-by-2 grid of graphs. Plot a sine wave in the first subplot.

x = linspace(-5,5); % define x
y1 = sin(x); % define y1 figure % create new figure
subplot(2,2,1) % first subplot
plot(x,y1)
title('First subplot')

Plot another sine wave in the second subplot.

y2 = sin(2*x); % define y2

subplot(2,2,2) % second subplot
plot(x,y2)
title('Second subplot')

Plot two more sine waves in the third and fourth subplots.

y3 = sin(4*x); % define y3
y4 = sin(6*x); % define y4 subplot(2,2,3) % third subplot
plot(x,y3)
title('Third subplot') subplot(2,2,4) % fourth subplot
plot(x,y4)
title('Fourth subplot')

Add Subplot Axis Labels

Add subplot labels using the xlabel and ylabel functions. By default, xlabel and ylabel label the current axes. The current axes is typically the last axes created or clicked with the mouse. Reissuing the command,subplot(m,n,p), makes the pth subplot the current axes.

Make the third subplot the current axes. Then, label its x-axis and y-axis.

subplot(2,2,3)
xlabel('x-axis')
ylabel('y-axis')

The figure contains four axes with a sine wave plotted in each axes.

更多:
http://www.mathworks.cn/cn/help/matlab/creating_plots/plotting-with-two-y-axes.html

matlab 画图的更多相关文章

  1. Matlab画图,坐标轴范围设置和间隔设置

    在Matlab画图的时候,系统默认的坐标轴范围以及间隔有时候并不是很合适,如何根据自己的要求来显示呢,Set语句就可以帮忙咯!! 1. set(gca,'xtick',0:100:2500)      ...

  2. Matlab画图-非常具体,非常全面

    Matlab画图 强大的画图功能是Matlab的特点之中的一个,Matlab提供了一系列的画图函数,用户不须要过多的考虑画图的细节,仅仅须要给出一些基本參数就能得到所需图形,这类函数称为高层画图函数. ...

  3. 设置 matlab 画图格式

    1:设置 matlab 画图格式 clear;clc; % load("array.mat"); % Bestallarray=array; % rllofcircle(Besta ...

  4. 如何解决 Matlab 画图时中文显示乱码的问题?

    使用的是win10系统,从前几个月某一天,我的matlab的figure里的中文都变成了口口.很是郁闷,还以为是动到了什么配置引起的. 前几天更新了matlab 2018b,发现还有这个问题.就觉得不 ...

  5. matlab 画图进阶

    matlab 画图进阶 applications of matlab in engineering 图表类型的选择 first:advanced 2d plots special plots logl ...

  6. matlab 画图技巧

    基本画图工具:matlab 画图中线型及颜色设置 matlab中坐标轴设置技巧 **Matlab中的坐标轴设置技巧**    axisoff;      %去掉坐标轴  axistight;      ...

  7. 20140513 matlab画图

    1.matlab画图 x1=[1.00E-06,2.00E-06,4.00E-06,9.00E-06,2.00E-05,4.00E-05,8.00E-05,2.00E-04,4.00E-04,7.00 ...

  8. matlab画图函数plot()/set/legend

    简单plot()/legend/XY轴范围axis 除了坐标轴信息外还可以添加其它的信息,如所画曲线的信息等:测试代码如下 x=0:pi/20:2*pi; y1=sin(x); y2=cos(x); ...

  9. MATLAB画图

    画图代码 clear % http://www.peteryu.ca/tutorials/matlab/visualize_decision_boundaries % load RankData % ...

  10. linux tomcat部署含有matlab画图打包的java web程序

    首先说下问题:matlab可以把相关算法代码打包成jar文件共java调用,本例使用的jar文件的作用是画图并保存,然后部署在linux的tomcat中进行发布.这里出现了一个问题,具体如下:linu ...

随机推荐

  1. linux 常见问题

    无root权限install do chmod u+w /etc/sudoers sudo vi /etc/sudoers 找到root   ALL=(ALL:ALL) ALL 在下面加一行: you ...

  2. 你所不知道的Html5那些事(一)

    文章简介:       关于html5相信大家早已经耳熟能详,但是他真正的意义在具体的开发中会有什么作用呢?相对于html,他又有怎样的新的定义与新理念在里面呢?为什么一些专家认为html5完全完成后 ...

  3. ios 单例模式(懒汉式)

    1. 单例模式的作用 可以保证在程序运行过程,一个类只有一个实例,而且该实例易于供外界访问 从而方便地控制了实例个数,并节约系统资源 2. 单例模式的使用场合 在整个应用程序中,共享一份资源(这份资源 ...

  4. Java实战之02Hibernate-08二级缓存

    十四.Hibernate的二级缓存 1.Hibernate的缓存结构 2.由于二级缓存被多线程共享,就必须有一定的事务访问策略 非严格读写:READ UNCOMMITTED 读写型:READ COMM ...

  5. bzoj2748:[HAOI2012]音量调节

    思路:刷水有益健康. #include<iostream> #include<cstdio> #include<cstring> #include<algor ...

  6. Java标准输入输出流的重定向及恢复

    在Java中输入输出数据一般(图形化界面例外)要用到标准输入输出流System.in和System.out,System.in,System.out默认指向控制台,但有时程序从文件中输入数据并将结果输 ...

  7. OpenJudge/Poj 1226 Substrings

    1.链接地址: http://bailian.openjudge.cn/practice/1226/ http://poj.org/problem?id=1226 2.题目: 总时间限制: 1000m ...

  8. WCF SOA服务应用

    WCF是微软官方推出的一个基于服务的整合框架,它整合了以前的Web Service.MSMQ.Remoting等通信技术,通过灵活的配置,让服务编程更加容易.可扩展.这篇文章主要目的就是带领大家从开发 ...

  9. AOP(以MVC中的过滤器为例)

    MVC里面的Filter public class AOPFilterAttribute : ActionFilterAttribute, IExceptionFilter { public void ...

  10. 虚拟机添加磁盘LVM分区

    参考博客:http://kimjinlsgd.blog.51cto.com/1918030/932210 一.查看磁盘情况 新添加一块磁盘. [root@VMhost /]# fdisk -l Dis ...