如何在 Octave 中绘制和显示正方形?
我无法在八度中绘制一个正方形。 我无法强制等比例缩放轴,因此我得到一个矩形:
以下试验不起作用:
x = [0, 1, 1, 0, 0]';
y = [0, 0, 1, 1, 0];
plot(x, y), axis equal, axis([-1,2, -1,2])
% figure('Position', [10,10,100,100]); %[startx,starty,width,height]
% plot(x, y)
可能我需要指定一个固定的窗口大小,同样 缩放轴。当第一个这样的展示窗口时我会很满意 将显示正确的正方形。豪华的解决方案将使窗户 (或其内容) 不能交互式调整大小。
备注:
- 我在 Windows XP 上有 Octave 3.2.4。
- Stackoverflow 中的建议 不起作用。
I cannot achieve to plot a square in Octave.
I cannot force equally scaled axes, so I am getting a rectangle instead:
The following trials are not working:
x = [0, 1, 1, 0, 0]';
y = [0, 0, 1, 1, 0];
plot(x, y), axis equal, axis([-1,2, -1,2])
% figure('Position', [10,10,100,100]); %[startx,starty,width,height]
% plot(x, y)
Probably I would need to specify a fixed window size and equally
scaled axes. I would be satisfied, when the first such display window
would show a correct square. A luxury solution would make the window
(or its content)
not interactively resizable.
Remarks:
- I have Octave 3.2.4 on Windows XP.
- The suggestion in Stackoverflow
does not work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信这是 Gnuplot 的
windows
输出设备的问题。将其与wxt
设备进行比较:Gnuplot 4.4.3、WinXP
请注意,对于“win 终端”,大小会影响图形大小,包括窗口标题栏和状态栏,而对于“wx 终端”它只设置内部绘图区域
Octave 3.4.2,WinXP
不幸的是,当我在 Octave,它仍然不是两种终端类型应有的样子。事实上,问题是使用
set(gcf,'position',[..])
调整图形大小没有效果:因此,我必须使用鼠标手动将图形大小调整为指定大小
(200,400)
(是的,我实际上拉了一个虚拟标尺并测量像素!)。最后调用refresh
命令重新绘制:好消息是,一旦正确设置了图形大小,
axis equal
就可以工作两种终端类型。另一方面,新的 FLTK 后端运行正常,没有任何黑客行为,因此您可能想切换到它:
MATLAB
作为参考,以下是 MATLAB 输出:
I believe this is an issue with Gnuplot's
windows
output device. Compare it against thewxt
device:Gnuplot 4.4.3, WinXP
Note that for the "win terminal", size affects the figure size including window title bar and status bar, while for the "wx terminal" it only sets the inner drawing area
Octave 3.4.2, WinXP
Unfortunately, when I tried this in Octave, it still was not what it should be for both terminal types. In fact, the problem is that resizing the figure using
set(gcf,'position',[..])
had no effect:Therefore, I had to manually resize the figures using the mouse to the specified size
(200,400)
(yes, I actually pulled a virtual ruler and measured the pixels!). Finally callrefresh
command to replot:The good news is that once you correctly set the figure size,
axis equal
is working for both terminals types.On the other hand, the new FLTK backend is behaving correctly without any hacks, so you might wanna switch to it:
MATLAB
For reference, here is the MATLAB output:
这对我有用(Linux 上的 Octave):
但是,这只在您调整图形窗口大小之前有效,所以我承认它有点烦躁。因此,为了使用 Octave 获得您想要的效果,我想您必须在调用 axis equal 之前放置图形窗口并进行所有更改。我多次调用 axis equal 的运气很差。
我猜想这与 GnuPlot 的限制有关(但我没有硬数据支持该说法),因此您可以尝试其他绘图库以查看是否表现出相同的行为。
编辑:
为了完整起见,我的代码生成的图(如果我不调整图形窗口大小)
如果您不这样做如果没有任何效果,您可以尝试调试您正在调用的 Octave 代码。在 MATLAB 中,您可以通过输入
edit axis
来检查相应的代码,但在 Octave 中,我想您必须提供axis.m
文件的完整路径(在帮助轴
)。This works for me (Octave on Linux):
However, this only works until you resize the figure window, so I admit it is a little fidgety. So to get what you want with Octave, I guess you will have to place your figure window and make all changes before calling
axis equal
. I had very little luck with callingaxis equal
multiple times.I guess this is related to limitations in GnuPlot (but I have no hard data supporting that claim), so you could try out other plotting libraries to see whether the exhibit the same behavior.
edit:
For completeness a plot of what my code produces (if I refrain from resizing the figure window)
If you don't get anything working, you can try to debug the Octave code you are calling. In MATLAB you can inspect the corresponding code by typing
edit axis
, but in Octave I guess you have to give the complete path to theaxis.m
file (which is mentioned inhelp axis
).