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


Python matplotlib.pyplot.semilogy()用法及代碼示例


Matplotlib是最流行的Python-ready軟件包,用於可視化數據。我們使用matplotlib繪製high-quality圖表,圖形和圖形。

matplotlib.pyplot.semilogy()函數

matplotlib庫的pyplot模塊中的matplotlib.pyplot.semilogy()函數用於繪製在y軸上具有對數刻度的圖。

用法: matplotlib.pyplot.semilogy(*args, **kwargs)

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

  • basey:此參數是y對數的底,並且是可選參數,默認值為10。
  • subsy:此參數是次要Y刻度的位置順序,並且是可選的。
  • nonposy:此參數是y中的一個非正值,可以將其屏蔽為無效值,或裁剪為非常小的正數。

返回值:這將返回以下內容:



  • 行:這將返回代表繪製數據的Line2D對象的列表。

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

# importing necessary libraries 
import matplotlib.pyplot as plot 
import numpy as np 
  
# Year data for the semilogy plot 
years = [1900, 1910, 1920, 1930, 1940, 1950, 
         1960, 1970, 1980, 1990, 2000, 2010,  
         2017] 
  
# index data - taken at end of every 
# decade - for the semilogy plot 
indexValues = [68, 81, 71, 244, 151, 200, 615, 
               809, 824, 2633, 10787, 11577, 
               20656] 
  
# Display grid 
plot.grid(True, which ="both") 
  
# Linear X axis, Logarithmic Y axis 
plot.semilogy(years, indexValues ) 
  
plot.ylim([10, 21000]) 
  
plot.xlim([1900, 2020]) 
  
# Provide the title for the semilogy plot 
plot.title('Y axis in Semilogy using Python Matplotlib') 
  
# Give x axis label for the semilogy plot 
plot.xlabel('Year') 
  
# Give y axis label for the semilogy plot 
plot.ylabel('Stock market index') 
  
# Display the semilogy plot 
plot.show()

輸出:
null

範例2:

# importing necessary libraries 
import matplotlib.pyplot as plt 
import numpy as np 
  
  
fig, ax = plt.subplots(nrows = 2, 
                      ncols = 2, 
                      figsize =(10, 5)) 
x = np.random.randn(1000) 
  
# Plot to each different index 
ax[0, 0].loglog(x, x / 2); 
ax[0, 1].semilogy(np.random.random(10), np.random.random(10)); 
ax[1, 0].semilogx(np.random.random(10), np.random.random(10)); 
ax[1, 1].hist(np.random.randn(1000));

輸出:
semilogy

範例3:

# importing necessary libraries 
import matplotlib.pyplot as plt 
import numpy as np 
  
  
x = [1, 2, 3, 4, 5] 
y = [11, 22, 33, 44, 55] 
  
fig, ax = plt.subplots() 
ax.semilogy(x, y);

輸出:
semilogy()




相關用法


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