Python MatPlotlib in Euler Math Toolbox

It seems to be less known that the Python packages Numpy and MathPlotlib can be used in Euler Math Toolbox (EMT). The plot in Python goes to a file, which can be inserted into the EMT notebook. Here is a simple example.

>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> x = np.arange(0,5,0.1)
>>> y = np.sin(x)
>>> plt.plot(x,y)
>pyins;

test-001

More elaborate examples can be found in the tutorial about Python. Here is a nice one. It is from the Python demos.

>function python pyvectors (n) ...
$  X,Y = np.mgrid[0:n,0:n]-n/2.0
$  T = np.arctan2(Y, X)
$  R = 10+np.sqrt(Y**2+X**2)
$  U,V = R*np.cos(T), R*np.sin(T)
$  plt.figure(figsize=[8,8])
$  plt.quiver(X,Y,U,V,R,alpha=0.5)
$  plt.quiver(X,Y,U,V,edgecolor='k',facecolor='None',linewidth=0.5)
$  plt.xlim(-n/2.0,n/2.0), plt.xticks([k-n/2.0 for k in range(0,n+1)])
$  plt.ylim(-n/2.0,n/2.0), plt.yticks([k-n/2.0 for k in range(0,n+1)])
$  endfunction
>pyvectors(8); pyins;

vectors

As you see, we park everything inside a function. The Numpy package is needed to allow vectorization of functions in Python. We could just as well compute the vectors X,Y,T,R,U,V in EMT and pass them to the function.

MatPlotlib, Numpy and other elements of Python are a welcome addition to the capabilities of EMT.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.