Open In App

Matplotlib.axes.Axes.get_yaxis_transform() in Python

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_yaxis_transform() Function

The Axes.get_yaxis_transform() function in axes module of matplotlib library is used to get the transformation used for drawing y-axis labels, ticks and gridlines.

Syntax: Axes.get_yaxis_transform(self, which=’grid’)

Parameters: This method does not accepts any parameters.

Return value: This method returns the transformation used for drawing y-axis labels, ticks and gridlines.

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

Example 1:




# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
   
   
t = np.arange(0.0, 5.0, 0.1)
s = np.exp(-t) + np.sin(2 * np.pi * t) + 1
nse = np.random.normal(0.0, 0.3, t.shape) * s
   
fig, vax = plt.subplots()
   
vax.plot(s, t, 'go-')
vax.hlines(t, [0], s)
vax.hlines([1, 2], 0, 1,
           transform = vax.get_yaxis_transform(),
           colors ='r')
   
fig.suptitle('matplotlib.axes.Axes.get_yaxis_transform()\
 function Example', fontweight ="bold")
   
plt.show()


Output:

Example 2:




# Implementation of matplotlib function
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
  
x = np.arange(0, 10, 0.005)
y = np.exp(-x / 2.) * np.sin(2 * np.pi * x)
  
fig, [ax, ax1] = plt.subplots(1, 2)
  
ax.plot(x, y)
ax.set_title("Without get_yaxis_transform() function")
  
ax1.plot(x, y, transform = ax1.get_yaxis_transform())
ax1.set_title("With get_yaxis_transform() function")
  
fig.suptitle('matplotlib.axes.Axes.get_yaxis_transform()\
 function Example', fontweight ="bold")
  
plt.show()


Output:



Last Updated : 19 Apr, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads