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


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

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

matplotlib.axes.Axes.format_cursor_data()函數

matplotlib庫的axiss模塊中的Axes.format_cursor_data()函數用於返回數據的字符串表示形式。

用法: Axes.format_cursor_data(self, data)


參數:此方法接受以下參數,如下所述:

  • data:此參數是用於使用的數據。

返回值:此方法返回數據的字符串表示形式。

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

範例1:

# Implementation of matplotlib function 
import numpy as np 
import matplotlib.pyplot as plt 
      
np.random.seed(10**7) 
geeksx = np.random.randn(10) 
  
fig, ax = plt.subplots() 
ax.plot(geeksx) 
  
ax.text(1.5, 0.85, "Value return by format_cursor_data():", 
        fontweight ="bold")  
  
ax.text(0, 0.7, ax.format_cursor_data(geeksx)) 
   
fig.suptitle('matplotlib.axes.Axes.format_cursor_data() \ 
function Example', fontweight ="bold") 
  
plt.show()

輸出:

範例2:

# Implementation of matplotlib function 
import numpy as np 
import matplotlib.pyplot as plt 
  
      
geeksx = np.array([24.40, 110.25, 20.05, 
                   22.00, 61.90, 7.80,  
                   15.00]) 
     
fig, ax = plt.subplots() 
ax.plot(geeksx, 'go-') 
  
ax.text(1, 95, "Value return by format_cursor_data():", 
        fontweight ="bold")  
  
ax.text(1.3, 85, ax.format_cursor_data(geeksx)) 
   
fig.suptitle('matplotlib.axes.Axes.format_cursor_data()\ 
function Example', fontweight ="bold") 
  
plt.show()

輸出:





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