Making a user-controllable plot

Out of the box, without requiring any additional packages, matplotlib offers primitives to add controllers on a figure so that a user can interact with it. In this recipe, we are going to see how to plot a famous parametric curve: the SuperShape curve. This curve is controlled by six parameters: A, B, M, N1, N2, and N3. These parameters determine the shape of the curve. They can be set interactively by the user by moving the cursor on the figure.

How to do it...

The following code will display a curve using pyplot.plot(), which at this point should be simple. However, we now use user interface elements (more commonly called widgets), that is, sliders. This can be done with the following steps:

  1. We start with the necessary ...

Get matplotlib Plotting Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.