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


Python Matplotlib.artist.Artist.format_cursor_data()用法及代碼示例

Matplotlib是Python中的一個庫,它是數字的-NumPy庫的數學擴展。 Artist類包含用於呈現到FigureCanvas中的對象的Abstract基類。圖中所有可見元素都是Artist的子類。

matplotlib.artist.Artist.format_cursor_data()方法

matplotlib庫的artist模塊中的format_cursor_data()方法用於獲取數據的字符串表示形式。

用法:Artist.remove_callback(self, data)


參數:此方法接受以下參數。

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

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

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

範例1:

# Implementation of matplotlib function 
import numpy as np 
import matplotlib.pyplot as plt 
from matplotlib.artist import Artist 
       
  
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, 
        Artist.format_cursor_data(ax, data = geeksx)) 
         
fig.suptitle('matplotlib.artist.Artist.format_cursor_data()\ 
function Example', fontweight ="bold")  
  
plt.show()

輸出:

範例2:

# Implementation of matplotlib function 
import numpy as np 
import matplotlib.pyplot as plt 
from matplotlib.artist import Artist 
        
  
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, 
        Artist.format_cursor_data(ax, 
                                  data = geeksx)) 
          
fig.suptitle('matplotlib.artist.Artist.format_cursor_data()\ 
function Example', fontweight ="bold")  
  
plt.show()

輸出:





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