Basic plot

These functions allow to display curves or values of a matrix.

imagesc

template<typename T>
inline void castor::imagesc(figure &fig, matrix<T> const &M)

Displays the data in a matrix using scaled colors.

plot

template<typename T = double>
inline void castor::plot(figure &fig, matrix<T> const &X, matrix<T> const &Y, std::vector<std::string> const &style = {""}, std::vector<std::string> const &label = {""})

Plots a 2D-curve Y = f(X) with customizable options.

Multiple plots can be given at once by giving Y as a multi-dimensional array. In that case, each line corresponds to a different plot. The customization options must be given as an array of strings (one string per plot). Each string may (but it is not mandatory) contain one of the following elements:

  • a line-style. If “-” is specified, the style is solid; otherwise the line will be dotted.

  • a marker-style which can be any of the following : “x” (cross), “o” (circle), “+” (plus sign), “d” (diamond), “s” (square).

  • a color which can be any of the following : “r” (red), “g” (green), “b” (blue), “y” (yellow), “c” (cyan), “m” (magenta), “k” (black) or “w” (white).

The same format should be used for the labels.

matrix<> X = linspace(0,10,100);
matrix<> Y = cos(X);

// plot y=sin(x) as a red solid line with cross markers
figure fig;
plot(fig,X,Y,{"r-x"});
drawnow(fig);

See plot3

plot3

template<typename T = double>
inline void castor::plot3(figure &fig, matrix<T> const &X, matrix<T> const &Y, matrix<T> const &Z, std::string const &style = "")

Plots curves defined by (X,Y,Z) in 3D-space, eventually linked by a styled line.

On the contrary to plot, only one curve can be given at a time.

See plot

spy

template<typename T>
inline void castor::spy(figure &fig, smatrix<T> const &Ms, std::string const &style = "", std::string const &label = "")

Spy sparse matrix non-zeros values.

smatrix<> Ms = speye(10);
figure fig;
spy(Ms,"b","Ms");
drawnow(fig);