开发者

How to plot and display a square in Octave?

开发者 https://www.devze.com 2023-04-04 11:00 出处:网络
I cannot achieve to plot a square in Octave. I cannot force equally scaled axes, so I am getting a rectangle instead:

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

How to plot and display a square in Octave?

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('Posi开发者_如何学Ction', [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.


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

How to plot and display a square in Octave?

How to plot and display a square in Octave?

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:

How to plot and display a square in Octave?

How to plot and display a square in Octave?

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

How to plot and display a square in Octave?


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])

How to plot and display a square in Octave?


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)

How to plot and display a square in Octave?

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).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号