Thursday, September 4, 2025
HomeLanguagesMatplotlib.axes.Axes.get_yaxis_transform() in Python

Matplotlib.axes.Axes.get_yaxis_transform() 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.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:

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32263 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6627 POSTS0 COMMENTS
Nicole Veronica
11799 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11858 POSTS0 COMMENTS
Shaida Kate Naidoo
6749 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6696 POSTS0 COMMENTS
Umr Jansen
6716 POSTS0 COMMENTS