Open In App

Matplotlib.axes.Axes.get_data_ratio() in Python

Last Updated : 30 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.get_data_ratio() Function

The Axes.get_data_ratio() function in axes module of matplotlib library is used to get the aspect ratio of the raw data.

Syntax: Axes.get_data_ratio(self)

Parameters: This method does not accepts any parameter.

Returns: This method return the aspect ratio of the raw data.

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

Example 1:




# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
   
fig, ax1 = plt.subplots()
   
x = np.random.randn(20, 50)
x[12, :] = 0.
x[:, 22] = 0.
  
ax1.spy(x)
ax1.set_title("Value Return by get_data_ratio : "
              +str(ax1.get_data_ratio())+"\n")
  
fig.suptitle('matplotlib.axes.Axes.get_data_ratio() \
Example')
  
plt.show()


Output:

Example 2:




# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
   
fig, [(ax1, ax2), (ax3, ax4)] = plt.subplots(2, 2)
   
x = np.random.randn(20, 50)
x[5, :] = 0.
x[:, 12] = 0.
   
ax1.spy(x, markersize = 4)
ax2.spy(x, precision = 0.2, markersize = 4)
   
ax3.spy(x)
ax4.spy(x, precision = 0.4)
  
ax1.set_title("Value Return by get_data_ratio : "
              +str(ax1.get_data_ratio())+"\n")
  
  
ax2.set_title("Value Return by get_data_ratio : "
              +str(ax2.get_data_ratio())+"\n")
  
ax3.set_title("Value Return by get_data_ratio : "
              +str(ax3.get_data_ratio())+"\n")
  
ax4.set_title("Value Return by get_data_ratio : "
              +str(ax4.get_data_ratio())+"\n")
  
fig.suptitle('matplotlib.axes.Axes.get_data_ratio\
 Example')
  
plt.show()


Output:



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads