##// END OF EJS Templates
Merge pull request #2728 from Carreau/shifttab...
Merge pull request #2728 from Carreau/shifttab also bind shift tab for tooltip + config This does not change the curent behavior, only add the shift+tab shortcut. Note that the shift tab shortcut has a slightly different behavior. You can select part of a line and pressing shift-tab will show you the tooltip only for the selection. This is disabled for multiline selection to still allow to unindent block of code, Keep in mind that the real real shortcut for indent unindent is Ctrl+] or [ . Select/tab is not really supported by codemirror. Finally the "tooltip_on_tab" behavior is globally configurable via IPython.config so that it could be easily switched to false. It can be overridden via js console for test purpose. IPython.config.tooltip_on_tab = true | false Take effect immediately, only on current notebook. or globally via custom.js var user_conf = {tooltip_on_tab:false | true}; $.extend(IPython.config, user_conf)

File last commit:

r8007:d835d46d
r8971:99339d10 merge
Show More
octavemagic_extension.ipynb
370 lines | 133.7 KiB | text/plain | TextLexer
/ docs / examples / notebooks / octavemagic_extension.ipynb

octavemagic: Octave inside IPythonΒΆ

InstallationΒΆ

The octavemagic extension provides the ability to interact with Octave. It depends on the oct2py package, which may be installed using easy_install.

To enable the extension, load it as follows:

InΒ [18]:
%load_ext octavemagic

OverviewΒΆ

Loading the extension enables three magic functions: %octave, %octave_push, and %octave_pull.

The first is for executing one or more lines of Octave, while the latter allow moving variables between the Octave and Python workspace. Here you see an example of how to execute a single line of Octave, and how to transfer the generated value back to Python:

InΒ [19]:
x = %octave [1 2; 3 4];
x
Out[19]:
array([[ 1.,  2.],
       [ 3.,  4.]])
InΒ [20]:
a = [1, 2, 3]

%octave_push a
%octave a = a * 2;
%octave_pull a
a
Out[20]:
array([[2, 4, 6]])

When using the cell magic, %%octave (note the double %), multiple lines of Octave can be executed together. Unlike with the single cell magic, no value is returned, so we use the -i and -o flags to specify input and output variables.

InΒ [21]:
%%octave -i x -o y
y = x + 3;
InΒ [22]:
y
Out[22]:
array([[ 4.,  5.],
       [ 6.,  7.]])

PlottingΒΆ

Plot output is automatically captured and displayed, and using the -f flag you may choose its format (currently, png and svg are supported).

InΒ [23]:
%%octave -f svg

p = [12 -2.5 -8 -0.1 8];
x = 0:0.01:1;

polyout(p, 'x')
plot(x, polyval(p, x));
12*x^4 - 2.5*x^3 - 8*x^2 - 0.1*x^1 + 8
No description has been provided for this image

The plot size is adjusted using the -s flag:

InΒ [24]:
%%octave -s 500,500

# butterworth filter, order 2, cutoff pi/2 radians
b = [0.292893218813452  0.585786437626905  0.292893218813452];
a = [1  0  0.171572875253810];
freqz(b, a, 32);
No description has been provided for this image
InΒ [25]:
%%octave -s 600,200 -f png

subplot(121);
[x, y] = meshgrid(0:0.1:3);
r = sin(x - 0.5).^2 + cos(y - 0.5).^2;
surf(x, y, r);

subplot(122);
sombrero()
No description has been provided for this image

Future workΒΆ

After the next release of oct2py, we'll add the ability to interrupt/kill the current Octave session without restarting the Python kernel.