matlab 画图
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 画图的更多相关文章
- Matlab画图,坐标轴范围设置和间隔设置
在Matlab画图的时候,系统默认的坐标轴范围以及间隔有时候并不是很合适,如何根据自己的要求来显示呢,Set语句就可以帮忙咯!! 1. set(gca,'xtick',0:100:2500) ...
- Matlab画图-非常具体,非常全面
Matlab画图 强大的画图功能是Matlab的特点之中的一个,Matlab提供了一系列的画图函数,用户不须要过多的考虑画图的细节,仅仅须要给出一些基本參数就能得到所需图形,这类函数称为高层画图函数. ...
- 设置 matlab 画图格式
1:设置 matlab 画图格式 clear;clc; % load("array.mat"); % Bestallarray=array; % rllofcircle(Besta ...
- 如何解决 Matlab 画图时中文显示乱码的问题?
使用的是win10系统,从前几个月某一天,我的matlab的figure里的中文都变成了口口.很是郁闷,还以为是动到了什么配置引起的. 前几天更新了matlab 2018b,发现还有这个问题.就觉得不 ...
- matlab 画图进阶
matlab 画图进阶 applications of matlab in engineering 图表类型的选择 first:advanced 2d plots special plots logl ...
- matlab 画图技巧
基本画图工具:matlab 画图中线型及颜色设置 matlab中坐标轴设置技巧 **Matlab中的坐标轴设置技巧** axisoff; %去掉坐标轴 axistight; ...
- 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 ...
- matlab画图函数plot()/set/legend
简单plot()/legend/XY轴范围axis 除了坐标轴信息外还可以添加其它的信息,如所画曲线的信息等:测试代码如下 x=0:pi/20:2*pi; y1=sin(x); y2=cos(x); ...
- MATLAB画图
画图代码 clear % http://www.peteryu.ca/tutorials/matlab/visualize_decision_boundaries % load RankData % ...
- linux tomcat部署含有matlab画图打包的java web程序
首先说下问题:matlab可以把相关算法代码打包成jar文件共java调用,本例使用的jar文件的作用是画图并保存,然后部署在linux的tomcat中进行发布.这里出现了一个问题,具体如下:linu ...
随机推荐
- 陷阱~SQL全表扫描与聚集索引扫描
SqlServer中在查询时,我们为了优化性能,通常会为where条件的字段建立索引,如果条件比较固定还会建立组合索引,接下来,我们来看一下索引与查询的相关知识及相关陷阱. SQL表自动为主键加聚集索 ...
- (二)JAVA使用POI操作excel
1,创建一个时间格式的单元格 Demo4.java package com.wishwzp.poi; import java.io.FileOutputStream; import java.util ...
- Apache中的权限设置
今天,我们的关注点就集中在 order deny,allow 这个语句中.在网上找了些资料,对它有了一些了解,写在这儿. 我们可能对apache中这个权限设置可能不太清楚,不同的顺序对权限到底 ...
- iOS开发——百度云推送
由于公司项目是集成的极光推送,详见下一篇博客. 集成百度推送大体相当,最好都参考官方文档集成,官方文档或官方网站教程是最好的博客. 百度Push服务SDK用户手册(iOS版) http://push. ...
- .net远程连接oracle数据库不用安装oracle客户端的方法
.net远程连接oracle数据库不用安装oracle客户端的方法步骤: 1.添加Sytem.Data.OracleClient命名空间. 2.连接时需要ConnectionString字符串,出现在 ...
- Array.splice返回值是数组
import flash.display.MovieClip; import flash.display.DisplayObject; var m:MovieClip = new MovieClip( ...
- CSS text-indent
text-indent 属性规定文本块中首行文本的缩进. 一个作用就是首行文本缩进,一般的文本都是首行缩进两个字符,这里就可以使用text-indent { text-indent: 2em; } 另 ...
- ajax、json一些整理(2)
<script type="text/javascript"> $(document).ready(function(){ $("#btn").cl ...
- Markdown语法备忘
标题 标题 标题是每篇文章都需要也是最常用的格式,在 Markdown 中,如果一段文字被定义为标题,只要在这段文字前加 # 号即可. # 一级标题 ## 二级标题 ### 三级标题 以此类推,总共六 ...
- CentOS安装mplayer
据说mplayer相当于windows下的暴风影音,那么今天就来安装上mplayer. 安装的大体步骤: 安装mplayer需要安装,解码器,mplayer,皮肤. 这三个包你都可以在mplayer官 ...