📌  相关文章
📜  Python中的 Matplotlib.axis.Axis.update_from()函数

📅  最后修改于: 2022-05-13 01:55:48.096000             🧑  作者: Mango

Python中的 Matplotlib.axis.Axis.update_from()函数

Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。它是Python中用于数组二维图的惊人可视化库,用于处理更广泛的 SciPy 堆栈。

matplotlib.axis.Axis.update_from()函数

matplotlib 库的轴模块中的Axis.update_from()函数用于将属性从其他复制到自身。

以下示例说明了 matplotlib.axis 中的 matplotlib.axis.Axis.update_from()函数:

示例 1:

Python3
# Implementation of matplotlib function
from matplotlib.axis import Axis
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): 
    Axis.update_from(prop1, prop2) 
    prop1.set_linewidth(7) 
    
plt.legend(handler_map ={plt.Line2D : HandlerLine2D(update_func = update)}) 
          
ax.set_title('matplotlib.axis.Axis.update_from() \
function Example', fontweight ="bold")  
    
plt.show()


Python3
# Implementation of matplotlib function
from matplotlib.axis import Axis
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)  
    Axis.update_from(shadow, l)  
          
    ot = mtransforms.offset_copy(l.get_transform(),  
                                 ax.figure,  
                                 x = 4.0,   
                                 y =-6.0,   
                                 units ='points')  
      
    shadow.set_transform(ot)       
plt.title('matplotlib.axis.Axis.update_from() \
function Example', fontweight ="bold")  
    
plt.show()


输出:

示例 2:

Python3

# Implementation of matplotlib function
from matplotlib.axis import Axis
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)  
    Axis.update_from(shadow, l)  
          
    ot = mtransforms.offset_copy(l.get_transform(),  
                                 ax.figure,  
                                 x = 4.0,   
                                 y =-6.0,   
                                 units ='points')  
      
    shadow.set_transform(ot)       
plt.title('matplotlib.axis.Axis.update_from() \
function Example', fontweight ="bold")  
    
plt.show() 

输出: