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


Python Matplotlib.axes.Axes.get_xscale()用法及代碼示例

Matplotlib是Python中的一個庫,它是數字的-NumPy庫的數學擴展。軸類包含大多數圖形元素:Axis,Tick,Line2D,Text,Polygon等,並設置坐標係。 Axes實例通過callbacks屬性支持回調。

matplotlib.axes.Axes.get_xscale()函數

matplotlib庫的axiss模塊中的Axes.get_xscale()函數用於將x軸刻度返回為字符串。

用法: Axes.get_xscale(self)


參數:此方法不接受任何參數。

返回:此函數以字符串形式返回x軸刻度。

以下示例說明了matplotlib.axes中的matplotlib.axes.Axes.set_yscale()函數:

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

輸出:

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

輸出:




相關用法


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