Examples below can be generated by plot_example.m
or plot_example.py
script in the Tools repository.
prepare_figure
function from the Tools can be used.
matlab | python |
---|---|
import matplotlib.pyplot as plt # assumed in every code bellow |
|
close all | plt.close( 'all' ) |
matlab | python |
---|---|
title( 'My title' ) | plt.title( 'My title' ) |
matlab | python |
---|---|
plot( …, 'DisplayName', 'Legend 1' ); | plt.plot( …, label='Legend 1' ) |
hold on | |
plot( …, 'DisplayName', 'Legend 2' ); | plt.plot( …, label='Legend 2' ) |
legend(); | plt.legend() |
matlab | python |
---|---|
do not use imshow | |
image( rgb_img ) or imagesc( grayscale_img ) | plt.imshow( img ) |
axis image [*] or axis equal | plt.axis( 'image' ) [*] or plt.axis( 'equal' ) |
[*] This hides area outside the image.
matlab | python | coment |
---|---|---|
plot( x, y, … ) | plt.plot( x, y, … ) | |
axis equal | plt.axis( 'equal' ) | scale |
xlabel( 'x' ); | plt.xlabel( 'x' ) | labels |
ylabel( 'y' ); | plt.ylabel( 'y' ) |
|
text( x, y, '\alpha' ) | plt.plot( x, y, 'a' ) | text |
Note that Matlab can plot greek numbers using TeX sequences ( '\\alpha', '\\beta', etc.).
matlab | python |
---|---|
from mpl_toolkits import mplot3d # 3D facilities, import before the .pyplot |
|
ax = plt.axes( projection='3d' ) # 3D axis must be explicitly created |
|
plot3( x, y, z, … ) | ax.plot3D( x, y, z, … ) |
text( x, y, z, … ) | ax.text3D( x, y, z, … ) |
axis( 'equal' ) | plt.axis( 'equal' ) |
zlabel( 'z' ); … | ax.set_zlabel( 'z' ) … |
quiver…
functions. Origin (X,Y,Z) and vector coordinates (dX,dY,dZ) must be given.
matlab | python |
---|---|
quiver(X,Y,dX,dY,0) [*] | plt.quiver(X,Y,dX,dY) |
ax = plt.axes( projection='3d' ) |
|
quiver3(X,Y,Z,dX,dY,dZ,0) [*] | ax.quiver3D(X,Y,Z,dX,dY,dZ) |
[*] The scaling argument 0 ensures the arrow is of the proper length.