HomeLanguagesMatplotlib.axes.Axes.has_data() in Python

Matplotlib.axes.Axes.has_data() in Python

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.has_data() Function

The Axes.has_data() function in axes module of matplotlib library is used to check if any artists have been added to axes.

Syntax: Axes.has_data(self)

Parameters: This method does not accepts any parameter.

Returns: This method return True if any artists have been added to axes.

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

Example 1:




# ImpleIn Reviewtation of matplotlib function  
import matplotlib.pyplot as plt
    
fig, ax1 = plt.subplots( )
ax1.set_xscale("log")
ax1.set_yscale("log")
ax1.set_adjustable("datalim")
  
ax1.plot([1, 3, 34, 4, 46, 3, 7, 45, 10],
         [1, 9, 27, 8, 29, 84, 78, 19, 48],
          "o-", color ="green")
  
ax1.set_xlim(1e-1, 1e2)
ax1.set_ylim(1, 1e2)
  
w = ax1.has_data()
  
print("Value Return by has_data() :", w)
   
fig.suptitle('matplotlib.axes.Axes.has_data()\
 function Example\n\n', fontweight ="bold")
  
fig.canvas.draw()
  
plt.show()


Output:

Value Return by has_data() : True

Example 2:




# ImpleIn Reviewtation of matplotlib function  
import matplotlib.pyplot as plt
import matplotlib.tri as tri
import numpy as np
     
n_angles = 36
n_radii = 10
min_radius = 2
radii = np.linspace(min_radius, 0.95, n_radii)
     
angles = np.linspace(0, 2 * np.pi, n_angles,
                     endpoint = False)
angles = np.repeat(angles[..., np.newaxis], 
                   n_radii, axis = 1)
angles[:, 1::2] += 2 * np.pi / n_angles
     
x = (radii * np.cos(angles)).flatten()
y = (radii * np.sin(angles)).flatten()
     
triang = tri.Triangulation(x, y)
     
triang.set_mask(np.hypot(x[triang.triangles].mean(axis = 1),
                         y[triang.triangles].mean(axis = 1))
                < min_radius)
fig, ax = plt.subplots()
     
ax.triplot(triang, 'bo-', lw = 1, color = "green")
  
w = ax.has_data()
  
print("Value Return by has_data() :", w)
   
fig.suptitle('matplotlib.axes.Axes.has_data() function\
 Example\n\n', fontweight ="bold")
  
fig.canvas.draw()
  
plt.show()


Output:

Value Return by has_data() : True
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32688 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7057 POSTS0 COMMENTS
Nicole Veronica
12198 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12293 POSTS0 COMMENTS
Shaida Kate Naidoo
7182 POSTS0 COMMENTS
Ted Musemwa
7447 POSTS0 COMMENTS
Thapelo Manthata
7160 POSTS0 COMMENTS
Umr Jansen
7150 POSTS0 COMMENTS