Open In App

Matplotlib.axes.Axes.set_picker() in Python

Last Updated : 21 Apr, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The Axes Class contains most of the figure elements: Axis, Tick, Line2D, Text, Polygon, etc., and sets the coordinate system. And the instances of Axes supports callbacks through a callbacks attribute.

matplotlib.axes.Axes.set_picker() Function

The Axes.set_picker() function in axes module of matplotlib library is used to define the picking behavior of the artist.

Syntax: Axes.set_picker(self, picker)

Parameters: This method accept the following parameters as discussed below:

  • picker : This parameter is used to set picking behavior. This can be None or bool or float or function.

Returns: This method the picking behavior of the artist.

Below examples illustrate the matplotlib.axes.Axes.set_picker() function in matplotlib.axes:

Example 1:




# Implementation of matplotlib function
import numpy as np
np.random.seed(19680801)
import matplotlib.pyplot as plt
  
     
volume = np.random.rayleigh(27, size = 40)
amount = np.random.poisson(7, size = 40)
ranking = np.random.normal(size = 40)
price = np.random.uniform(1, 7, size = 40)
     
fig, ax = plt.subplots()
     
scatter = ax.scatter(volume * 2
                     amount**3,
                     c = ranking**3,
                     s = price**3,
                     vmin = -3,
                     vmax = 3,
                     cmap ="Spectral")
  
ax.set_picker(4)
    
fig.suptitle('matplotlib.axes.Axes.set_picker() \
function Example', fontweight ="bold")
  
plt.show()


Output:

Example 2:




# Implementation of matplotlib function
import numpy as np
import matplotlib.pyplot as plt
  
  
X = np.random.rand(10, 200)
xs = np.mean(X, axis = 1)
ys = np.std(X, axis = 1)
  
fig = plt.figure()
ax = fig.add_subplot(111)
line, = ax.plot(xs, ys, 'go-')
  
ax.set_picker(True)
    
fig.suptitle('matplotlib.axes.Axes.set_picker()\
 function Example', fontweight ="bold")
plt.show()


Output:



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads