當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python Matplotlib.pyplot.xscale()用法及代碼示例

Matplotlib是Python中的一個庫,它是數字的-NumPy庫的數學擴展。 Pyplot是Matplotlib模塊的基於狀態的接口,該模塊提供了MATLAB-like接口。可在Pyplot中使用的各種圖線圖,輪廓圖,直方圖,散點圖,3D圖等。

matplotlib.pyplot.xscale()函數

matplotlib庫的pyplot模塊中的xscale()函數用於設置x軸比例。

用法: matplotlib.pyplot.xscale(value, \*\*kwargs)

參數:此方法接受下麵描述的以下參數:

  • value:此參數是要應用的軸比例類型。
  • **kwargs:有不同的關鍵字參數可以接受,並且取決於規模。

返回值:此方法不返回任何值。



以下示例說明了matplotlib.pyplot中的matplotlib.pyplot.xscale()函數:

範例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() 

輸出:

範例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() 

輸出:




相關用法


注:本文由純淨天空篩選整理自SHUBHAMSINGH10大神的英文原創作品 Matplotlib.pyplot.xscale() function in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。