

#PlottingĪxes defining the space in which the button will be located To this purpose, we entirely rely on the matplotlib.pyplotpackage. In the next step we define the plotting window and plot our function. All these procedures are described in the following code-lines. Of course, this is only one possible example, any function is good for the final goal of this article. The “y” array is defined by the following function:īoth the sin() and the exponential function are introduced using NumPy. linspace(), which will generate an array of 100 equally spaced numbers from 0 to 10. The “x” array is defined by exploiting the NumPy function.

In order to use our cursor on a real plot, we introduce an initial function by defining two NumPy arrays, “x” and “y”. Finally, from the matplotlib.widgetpackage, we import the function Cursor, which will be used for the creation of the interactive cursor. We will use NumPyfor defining an initial function that will be then displayed using matplotlib.pyplot. Accessing the Stored Values Outside the FunctionĪs to begin, we import the libraries and the packages that will be used in this example.Displaying the point coordinates in the annotating box.Storing the values outside the function.

Storing and Displaying the Coordinates of the Selected Point.# Unzipping the coord list in two different arrays # printing the values of the selected pointįig.canvas.mpl_connect('button_press_event', onclick) # Function for storing and showing the clicked values #x and y arrays for definining an initial functionĬursor = Cursor(ax, horizOn=True, vertOn=True, useblit=True,Īnnot = ax.annotate("", xy=(0,0), xytext=(-40,40),textcoords="offset points",ībox=dict(boxstyle='round4', fc='linen',ec='k',lw=1),
OPEN CANVAS 6 CURSOR OFFSET CODE
Every time a point on the window is clicked with the cursor, an annotating box containing the values of the point coordinates is displayed.Īnd here’s the code that we’ll discuss in this article that leads to this output: import numpy as np
