How to add the basic GUI neutral widgets

We will begin by taking a look at cursor. The cursor will generate a widget that places little x axis and y axis cursors over the top of the axis. The first argument to any widget is the axis that we want to attach it to. In this case, we want to attach it to the current axis. By doing this, by default, it should look unchanged.

  1. However, as we hover over the plot, we get the XY cursor, as shown in the following output after the code:
# Basic cursor
nums = np.arange(0,10,0.1)
plt.plot(nums, np.sin(nums))
Cursor(plt.gca())

Following is the output of the preceding code:

  1. As we change the attributes, for example when we change the line width to any other line property (which also changes the color):
# Basic cursor
nums = np.arange(0,10,0.1)
plt.plot(nums, np.sin(nums))
Cursor(plt.gca(), linewidth=5, color='r')

We will get the following output:

The GUI neutral widgets in Matplotlib are actually modifications to the figure object so that they don't apply widgets to other parts of the code like ipywidgets did, where it was using the Jupyter Notebook CEL outputs. Anything that can render a figure can render these GUI neutral widgets, as long as the backend is interactive.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.108.196