Skip to main content

Using notebooks

A .NET notebook is a .dib file that contains snippets of code, called cells, which you can individually run to immediately see their outputs.

They are useful to show and discuss code step by step, as we do in our examples, but also to be modified and try things out.

Running a cell in VS Code.

Copy the preamble!

You may want to create your own notebooks to test things.

At the time of writing, notebooks are like single-file programs, they may reference other libraries (using either Nuget or local .dll) but you cannot use something like include to pick code from elsewhere.

Thus you must copy the preamble that you find at the start of the example notebooks (you will find where it ends clearly marked). This preamble loads the necessary libraries, and defines the plot() function.

The plot() function

Plotting is not a feature of Nancy, per se. As a computational library, it focuses on data structures and algorithms, leaving higher-level operations such as plotting to the applications using it.

For this use-case, as it is really important to see what a Curve looks like for tutorials and experimenting, we implemented plot() (with various overloads) to make is easy and immediate to try the library.

Example of use: the call plot(...) generates the image below the notebook cell.
caution

plot() is designed and tested only for simple visualizations in notebooks. For other contexts and uses you may need something different.

You can use plot() to visualize one or more Curve or Sequence objects. Many overloads are available:

  • plot(curve, name, limit): plots the given curve from 0 to limit, using name for the legend.
  • plot(curves, names, limit): plots the given list of curves from 0 to limit, using the corresponding names for the legend.
  • plot(sequence, name, limit): plots the given sequence, using name for the legend.
  • plot(sequences, names, limit): plots the given list of sequences, using the corresponding names for the legend.

You can omit the names, in which case { a, b, c, ... } will be used instead. For Curves, you can omit the time limit, in which case the function will compute a default one.

With the overloads described above, you will have to explicitly declare the lists, e.g.

var sc = new Curve( ... );
var ac = new Curve( ... );
plot(
new []{sc, ac}, // Curve[]
new []{"sc", "ac"}, // string[]
);

However, if none of the optional arguments is provided, you can use an even simpler syntax

plot(sc, ac);   // they will be called "a" and "b" in the legend