MATLAB 函数绘图和直线有何不同?
MATLAB 中的函数 plot
和 line
有什么区别?他们在做同样的事情吗?
What's the difference between the functions plot
and line
in MATLAB? Are they doing the same thing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
函数
plot
和line
做几乎相同的事情,但是plot
是一个高级函数,可能与其他图形对象有更多的交互。可以找到高级和低级函数的简要摘要 此处。像plot
这样的高级函数很可能在内部调用像line
这样的原始函数来创建它们的图形,但它们也可以修改或与其父级 轴 或 图。来自line
:例如,如果您调用
line
函数:MATLAB 使用指定的数据值在当前坐标区中绘制一条红线。如果没有轴,MATLAB 将创建一个。如果没有用于创建坐标区的图窗窗口,MATLAB 也会创建它。
如果您第二次调用
line
函数,MATLAB 将在当前坐标区中绘制第二条线,而不擦除第一条线。此行为不同于诸如plot
之类的高级函数,后者删除图形对象并重置所有轴属性(位置
和单位
)。您可以使用hold< 来更改高级函数的行为/code>
命令或通过更改轴的设置
NextPlot
属性。plot
和line
函数也会以不同的方式影响自动线条着色,如此处< /a>.The functions
plot
andline
do nearly the same thing, butplot
is a high-level function that may have more interaction with other graphics objects. A brief summary of high-level and low-level functions can be found here. High-level functions likeplot
are likely internally calling primitive functions likeline
to create their graphics, but they can also modify or interact with properties of their parent axes or figure. From the documentation forline
:For example, if you call the
line
function:MATLAB draws a red line in the current axes using the specified data values. If there is no axes, MATLAB creates one. If there is no figure window in which to create the axes, MATLAB creates it as well.
If you call the
line
function a second time, MATLAB draws the second line in the current axes without erasing the first line. This behavior is different from high-level functions likeplot
that delete graphics objects and reset all axes properties (exceptPosition
andUnits
). You can change the behavior of high-level functions by using thehold
command or by changing the setting of the axesNextPlot
property.The
plot
andline
functions also differently affect automatic line coloring, as show here.plot()
用于创建图形,通常是某种折线图。line()
创建一个 lin 对象,该对象可能出现在图形中。不,他们没有做同样的事情。我通常使用plot
创建图形,使用line
向现有图形添加线条。如果这不能回答您的问题,请查看详细介绍这些问题的文档。
plot()
is used to create a graphic, usually a line graph of some sort.line()
creates a lin object which may appear in, say, a graphic. No they're not doing the same thing. I'd usually useplot
for creating a graphic,line
for adding lines to an existing graphic.If this doesn't answer your question, have a look at the documentation which covers these matters in great detail.