plot function overwrites axes
显示 更早的评论
When specifying the axes for a plot, I assumed one can create a figure-handle, axes-handle, and then plot to an axes.
Can someone please explain to me, why the plot command seems to overwrite ax1?
% hold(ax1, "on")
before the plot command would solve the problem. Is it really neccessary to hold on the axes, specified in the plot command?
fig1 = figure(1);
ax1 = axes("Parent",fig1);
axis(ax1, [-1 1 -1 1]);
ax1.XAxisLocation = "origin";
ax1.YAxisLocation = "origin";
x = [-1,2,3,4];
y = x.*2;
plot(ax1,x,y,"r-x")
采纳的回答
更多回答(1 个)
Walter Roberson
2023-2-6
2 个投票
Unless you have "hold on" (or the internal equivalent property) then each time you use a "high-level" graphics call, MATLAB does a cla() on the axes if it already exists.
You either need to hold on or else set the axes properties after you plot()
2 个评论
Peter Dittrich
2023-2-7
Walter Roberson
2023-2-7
It used to be relatively easy to distinguish between "high-level" or not: you looked at the types of the objects returned by plotting routines, and those were always in terms of low-level objects.
In the past, plotting routines used to build everything out of line() objects, surface() objects, patch() objects, text() objects, scatter() objects, and image() objects. Higher level functions included functions such as plot() and surf() and contour(); those would go through code that initialized the axes if NextPlot was 'replace' or 'replace'. patch() was an exception in that it was both high level and low level: if you called it passing in matrices of data then it was high level, but if you only passed in properties using name/value pairs then it was low-level.
These days, there are a lot of specialized graphics objects with dubious justification, and it is not always clear whether they are high-level or low-level.
类别
在 帮助中心 和 File Exchange 中查找有关 Graphics Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

