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


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

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

matplotlib.axes.Axes.update_from()函數

matplotlib庫的axiss模塊中的Axes.update_from()函數用於將屬性從其他屬性複製到自身。

用法: Axes.update_from(self, other)


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

  • other:此參數是要更新的屬性。

返回值:此方法返回藝術家所有屬性的字典。

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

範例1:

# Implementation of matplotlib function  
import numpy as np 
import matplotlib.pyplot as plt 
from matplotlib.legend_handler import HandlerLine2D 
  
  
x = np.linspace(0, 3 * np.pi) 
y1 = np.sin(x) 
y2 = np.cos(x) 
  
fig = plt.figure() 
  
ax = fig.add_subplot(111) 
ax.plot(x, y1, c ='b', label ='y1', linewidth = 1.0) 
ax.plot(x, y2, c ='g', label ='y2') 
  
linewidth = 7
  
def update(prop1, prop2):
    prop1.update_from(prop2) 
    prop1.set_linewidth(7) 
  
plt.legend(handler_map ={plt.Line2D:HandlerLine2D(update_func = update)}) 
  
fig.suptitle('matplotlib.axes.Axes.update_from()\ 
 function Example', fontweight ="bold")  
  
plt.show() 

輸出:

範例2:

# Implementation of matplotlib function  
import numpy as np  
import matplotlib.pyplot as plt 
import matplotlib.transforms as mtransforms 
  
      
fig, ax = plt.subplots()  
l1, = ax.plot([0.1, 0.5, 0.9],  
              [0.1, 0.9, 0.5],  
              "bo-") 
l2, = ax.plot([0.1, 0.5, 0.9], 
              [0.5, 0.2, 0.7],  
              "ro-") 
  
for l in [l1, l2]:
      
    xx = l.get_xdata() 
    yy = l.get_ydata() 
      
    shadow, = ax.plot(xx, yy) 
    shadow.update_from(l) 
      
    ot = mtransforms.offset_copy(l.get_transform(), 
                                 ax.figure, 
                                 x = 4.0,  
                                 y =-6.0,  
                                 units ='points') 
  
    shadow.set_transform(ot) 
  
fig.suptitle('matplotlib.axes.Axes.update_from() \ 
function Example', fontweight ="bold")  
  
plt.show() 

輸出:




相關用法


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