Saturday, November 16, 2024
Google search engine
HomeLanguagesMatplotlib.axes.Axes.get_xaxis_transform() in Python

Matplotlib.axes.Axes.get_xaxis_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_xaxis_transform() Function

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

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

Parameters: This method does not accepts any parameters.

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

Below examples illustrate the matplotlib.axes.Axes.get_xaxis_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(t, s, 'go-')
vax.vlines(t, [0], s)
vax.vlines([1, 2], 0, 1,
           transform = vax.get_xaxis_transform(),
           colors ='r')
  
fig.suptitle('matplotlib.axes.Axes.get_xaxis_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_xaxis_transform() function")
  
ax1.plot(x, y, transform = ax1.get_xaxis_transform())
ax1.set_title("With get_xaxis_transform() function")
  
fig.suptitle('matplotlib.axes.Axes.get_xaxis_transform()\
 function Example', fontweight ="bold")
  
plt.show()


Output:

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

Most Popular

Recent Comments