7. Introduction to the Examples¶

This section gives an overview of the use of PySpice by means of examples inspired from typical circuits, which can also serve as learning materials.

Usually these examples don’t involve advanced Python programming. You just need to know basic Python programming and how to use the Numpy and Matplotlib framework. However the code to make complex plots can require advanced Matplotlib skills.

Each example features a banner with a download icon just after the file name and a button (>>>) on the right to show the content of the file.

7.2. How to Run these Examples¶

There are several ways to run the examples: as a script from the console, in the IPython interactive environment or in a web browser using a IPython Notebook. Each of them has their advantages and drawbacks. A script is best when we want to work on a file using an editor, and an interactive environment is best when we want to play with code interactively.

To run an example from the console, execute this command:

python examples/.../foo.py


To start the interactive IPython environment, execute one of these commands:

ipython --matplotlib       # enable matplotlib integration
ipython --matplotlib-qt    # enable matplotlib integration with qt4 backend
ipython qtconsole          # start the qtconsole GUI application


then run an example using the magic command:

%run examples/../foo.py


ipython notebook


When we use IPython notebook, it is convenient to use a Matplotlib backend that outputs the graphics embedded in the notebook file. To activate this backend, somewhere in the beginning on the notebook, you must add:

%matplotlib inline


Then you can copy-paste code blocks and execute them.

7.3. How to Write a Netlist¶

Obviously it is not easy to write a netlist from scratch. The best approach is to make a quick sketch and to bless each node. However you can also use a schematic capture progam like Kicad and then export the netlist to SPICE.