如何在 Octave 中绘制和显示正方形?

发布于 2024-12-04 04:33:18 字数 572 浏览 1 评论 0原文

我无法在八度中绘制一个正方形。 我无法强制等比例缩放轴,因此我得到一个矩形:

在此处输入图像描述

以下试验不起作用:

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)

可能我需要指定一个固定的窗口大小,同样 缩放轴。当第一个这样的展示窗口时我会很满意 将显示正确的正方形。豪华的解决方案将使窗户 (或其内容) 不能交互式调整大小。

备注:

  1. 我在 Windows XP 上有 Octave 3.2.4。
  2. Stackoverflow 中的建议 不起作用。

I cannot achieve to plot a square in Octave.
I cannot force equally scaled axes, so I am getting a rectangle instead:

enter image description here

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:

  1. I have Octave 3.2.4 on Windows XP.
  2. The suggestion in Stackoverflow
    does not work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

债姬 2024-12-11 04:33:18

我相信这是 Gnuplot 的 windows 输出设备的问题。将其与 wxt 设备进行比较:

Gnuplot 4.4.3、WinXP

# Gnuplot, wxWidgets terminal
set terminal wxt size 200,400
set size ratio -1        # set size square
plot x

# Gnuplot, Windows terminal
set terminal windows size 200,400
set size ratio -1        # set size square
plot x

gnuplot_wxWidgets_terminal
gnuplot_Windows_terminal

请注意,对于“win 终端”,大小会影响图形大小,包括窗口标题栏和状态栏,而对于“wx 终端”它只设置内部绘图区域


Octave 3.4.2,WinXP

不幸的是,当我在 Octave,它仍然不是两种终端类型应有的样子。事实上,问题是使用 set(gcf,'position',[..]) 调整图形大小没有效果:

# Octave, backend=Gnuplot, terminal=wxt/windows
graphics_toolkit gnuplot     # backend gnuplot
setenv('GNUTERM','wx')       # wx/windows
figure, set(gcf,'position',[100 100 200 400])
plot(-10:10, -10:10, 'r'), legend('x')
axis([-10 10 -10 10])
axis equal                   # axis square

因此,我必须使用鼠标手动将图形大小调整为指定大小(200,400) (是的,我实际上拉了一个虚拟标尺并测量像素!)。最后调用 refresh 命令重新绘制:

octave_gnuplot_wx_resized
octave_gnuplot_windows_resized

好消息是,一旦正确设置了图形大小,axis equal 就可以工作两种终端类型。

另一方面,新的 FLTK 后端运行正常,没有任何黑客行为,因此您可能想切换到它:

# Octave, backend=FLTK
graphics_toolkit fltk        # backend fltk
figure, set(gcf,'position',[100 100 200 400])
plot(-10:10, -10:10, 'r'), legend('x')
axis([-10 10 -10 10])
axis equal

octave_fltk


MATLAB

作为参考,以下是 MATLAB 输出:

%# MATLAB
figure, set(gcf,'position',[100 100 200 400])
plot(-10:10, -10:10, 'r'), legend('x')
axis equal
axis([-10 10 -10 10])

matlab

I believe this is an issue with Gnuplot's windows output device. Compare it against the wxt device:

Gnuplot 4.4.3, WinXP

# Gnuplot, wxWidgets terminal
set terminal wxt size 200,400
set size ratio -1        # set size square
plot x

# Gnuplot, Windows terminal
set terminal windows size 200,400
set size ratio -1        # set size square
plot x

gnuplot_wxWidgets_terminal
gnuplot_Windows_terminal

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:

# Octave, backend=Gnuplot, terminal=wxt/windows
graphics_toolkit gnuplot     # backend gnuplot
setenv('GNUTERM','wx')       # wx/windows
figure, set(gcf,'position',[100 100 200 400])
plot(-10:10, -10:10, 'r'), legend('x')
axis([-10 10 -10 10])
axis equal                   # axis square

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 call refresh command to replot:

octave_gnuplot_wx_resized
octave_gnuplot_windows_resized

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:

# Octave, backend=FLTK
graphics_toolkit fltk        # backend fltk
figure, set(gcf,'position',[100 100 200 400])
plot(-10:10, -10:10, 'r'), legend('x')
axis([-10 10 -10 10])
axis equal

octave_fltk


MATLAB

For reference, here is the MATLAB output:

%# MATLAB
figure, set(gcf,'position',[100 100 200 400])
plot(-10:10, -10:10, 'r'), legend('x')
axis equal
axis([-10 10 -10 10])

matlab

中性美 2024-12-11 04:33:18

这对我有用(Linux 上的 Octave):

x = [0, 1, 1, 0, 0]';
y = [0, 0, 1, 1, 0];
plot(x, y)
axis([-1,2, -1,2])
axis equal % or axis square

但是,这只在您调整图形窗口大小之前有效,所以我承认它有点烦躁。因此,为了使用 Octave 获得您想要的效果,我想您必须在调用 axis equal 之前放置图形窗口并进行所有更改。我多次调用 axis equal 的运气很差。

我猜想这与 GnuPlot 的限制有关(但我没有硬数据支持该说法),因此您可以尝试其他绘图库以查看是否表现出相同的行为。

编辑
为了完整起见,我的代码生成的图(如果我不调整图形窗口大小)

在此处输入图像描述

如果您不这样做如果没有任何效果,您可以尝试调试您正在调用的 Octave 代码。在 MATLAB 中,您可以通过输入 edit axis 来检查相应的代码,但在 Octave 中,我想您必须提供 axis.m 文件的完整路径(在帮助轴)。

This works for me (Octave on Linux):

x = [0, 1, 1, 0, 0]';
y = [0, 0, 1, 1, 0];
plot(x, y)
axis([-1,2, -1,2])
axis equal % or axis square

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 calling axis 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)

enter image description here

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 the axis.m file (which is mentioned in help axis).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文