Matplotlib.pyplot.xscale() function in Python
Last Updated :
05 Jun, 2020
Improve
Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. There are various plots which can be used in Pyplot are Line Plot, Contour, Histogram, Scatter, 3D Plot, etc.
matplotlib.pyplot.xscale() function
The xscale() function in pyplot module of matplotlib library is used to set the x-axis scale.
Syntax: matplotlib.pyplot.xscale(value, \*\*kwargs)
Parameters: This method accept the following parameters that are described below:
- value: This parameter is the axis scale type to apply.
- **kwargs: There are different keyword arguments which are accepted and its depend on the scale.
Returns: This method does not returns any value.
Below examples illustrate the matplotlib.pyplot.xscale() function in matplotlib.pyplot:
Example 1:
Python3
# 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 plt.xscale( 'log' ) plt.plot(xs, ys) plt.xlabel( 'Frequency' ) plt.title('matplotlib.pyplot.xscale() \ function Example\n', fontweight = "bold" ) plt.show() |
Output:
Example 2:
Python3
# Implementation of matplotlib function import numpy as np import matplotlib.pyplot as plt fig, ax4 = plt.subplots() x = 10.0 * * np.linspace( 0.0 , 2.0 , 15 ) y = x * * 2.0 plt.xscale( "log" , nonposx = 'clip' ) plt.yscale( "log" , nonposy = 'clip' ) plt.errorbar(x, y, xerr = 0.1 * x, yerr = 2.0 + 1.75 * y, color = "green" ) plt.ylim(bottom = 0.1 ) plt.title('matplotlib.pyplot.xscale() \ function Example\n', fontweight = "bold" ) plt.show() |
Output: