先前讲解了简单绘图方法: 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 xlim, ylim, 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. WCF编程系列(六)以编程方式配置终结点

    WCF编程系列(六)以编程方式配置终结点   示例一中我们的宿主程序非常简单:只是简单的实例化了一个ServiceHost对象,然后调用open方法来启动服务.而关于终结点的配置我们都是通过配置文件来 ...

  2. (poj)1502 MPI Maelstrom

    题目链接:http://poj.org/problem?id=1502 Description BIT has recently taken delivery of their processor A ...

  3. [翻译][MVC 5 + EF 6] 8:更新相关数据

    原文:Updating Related Data with the Entity Framework in an ASP.NET MVC Application 1.定制Course的Create和E ...

  4. 【nodemailer】 之邮件附件

    nodemailer 续 之前对nodemailer做了一个简单的了解,这篇文章主要研究一下如何添加附加文件 测试代码 //Created by yyrdl on 2015/10/2. var nod ...

  5. asp.net弹出框后页面走样

    1.去掉language='javascript' ,问题依旧 2.后面加上Response.Write("<script>document.location=document. ...

  6. centos coreseek 快速安装

    CoreSeek快速安装: 安装前,建议查看:源码包说明README:4.0/4.1版可参考3.2版本安装,步骤相同:如遇到问题,请看详细安装说明. ##下载coreseek:coreseek 3.2 ...

  7. JSP Ajax

    html代码: <!DOCTYPE html> <html> <script> function display() { var div=document.getE ...

  8. Jquery Offset, Document, Window 都是什么

    From http://www.cnblogs.com/luhe/archive/2012/11/14/2769263.html   JQuery Offset实验与应用 我们有时候需要实现这样一种功 ...

  9. 微信公众号-5秒内不回复测试并处理方案,顺便复习php 时间执行

    在index.php中 file_put_contents('has_request.txt','请求时间:'.date('YmdHis')."\n",FILE_APPEND); ...

  10. 使用vagrant作为开发环境后,js报错

    当你尝试修改一个js,并且用同样的方法更新之后,会遇到类似的问题,是的,就算重启VM上任何服务,甚至重启VM,依旧没有用,当然,比起其他资源文件,浏览器的反应会强烈一些,因为浏览器会提示未知错误,而你 ...