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 ...
随机推荐
- oracle 表空间常用语句
–查询表空间使用情况 SELECT UPPER(F.TABLESPACE_NAME) "表空间名", D.TOT_GROOTTE_MB "表空间大小(M)", ...
- Ext.Net学习笔记20:Ext.Net FormPanel 复杂用法
Ext.Net学习笔记20:Ext.Net FormPanel 复杂用法 在上一篇笔记中我们介绍了Ext.Net的简单用法,并创建了一个简单的登录表单.今天我们将看一下如何更好是使用FormPanel ...
- 怎样向IT行业的朋友说明《圣经》的重要性
“世界的官方文档”——怎么样?
- Merge Into example
merge into users a using temp_users b on (a.userid = b.user_id) when matched then update set a.passw ...
- static的应用以及静态与非静态的区别
先前看到一个技术大牛写了一个关于静态成员与非静态成员,静态方法和非静态方法的各自区别,觉得挺好的,在这里写一个小程序来说明这些区别. package com.liaojianya.chapter5; ...
- 暑假集训(2)第七弹 -----今年暑假不AC(hdu2037)
J - 今年暑假不AC Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:32768KB 64 ...
- config spec
config_spec Rules for selecting versions of elements to appear in a view APPLICABILITY Product Comma ...
- Ubuntu下GCC的安装以及版本控制
在Ubuntu下安装GCC和其他一些Linux系统有点不一样. 方法一: 该方法超简单:sudo apt-get build-depgcc 就上面这条命令就可以搞定 方法二:sudo apt-get ...
- 最大类间方差法(Otsu)
由Otsu(大津展之)于1978年提出的最大类间方差法,是引起较多关注的一种阈值选取方法.它是在判决分析或最小二乘原理的基础上推导出来的. 参考文献: [1] Otsu N. A threshold ...
- C# 实体model验证输出
新建Model实体: [Required(ErrorMessage = @"地址 1 为必填项!")] [StringLength(, ErrorMessage = @" ...