Thursday, July 4, 2024
HomeLanguagesPythonMatplotlib.axes.Axes.get_xscale() in Python

Matplotlib.axes.Axes.get_xscale() 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_xscale() Function

The Axes.get_xscale() function in axes module of matplotlib library is used to return the x-axis scale as string.

Syntax: Axes.get_xscale(self)

Parameters: This method does not accepts any parameters.

Return: This function return the x-axis scale as a string.

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

Example 1:




# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
Ā Ā Ā Ā Ā Ā 
fig, ax = plt.subplots()
Ā Ā Ā 
ax.plot([1, 2, 3])
Ā Ā Ā 
w = ax.get_xscale()
Ā Ā Ā 
ax.set_title("xscale property : "+ str(w),
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā fontweight ="bold")
fig.suptitle('matplotlib.axes.Axes.get_xscale()\
Ā function Example\n', fontweight ="bold")
Ā Ā 
fig.canvas.draw()
plt.show()


Output:

Example 2:




# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.ticker import EngFormatter
Ā Ā Ā 
val = np.random.RandomState(19680801)
xs = np.logspace(1, 9, 100)
ys = (0.8 + 4 * val.uniform(size = 100)) * np.log10(xs)**2
Ā Ā Ā 
fig, ax0 = plt.subplots()
ax0.set_xscale('log')
formatter0 = EngFormatter(unit ='Hz')
ax0.xaxis.set_major_formatter(formatter0)
ax0.plot(xs, ys)
ax0.set_xlabel('Frequency')
Ā Ā 
w = ax0.get_xscale()
Ā Ā Ā 
ax0.set_title("xscale property : "+ str(w),
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā fontweight ="bold")
fig.suptitle('matplotlib.axes.Axes.get_xscale()\
Ā function Example\n', fontweight ="bold")
Ā Ā 
fig.canvas.draw()
plt.show()


Output:

Thapelo Manthata
Iā€™m a desktop support specialist transitioning into a SharePoint developer role by day and Software Engineering student by night. My superpowers include customer service, coding, the Microsoft office 365 suite including SharePoint and power platform.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments