我正在撰寫的課程的一部分是使用 matplotlib 進行繪圖的包裝器。
但是,我希望我的包裝器仍然能夠傳遞所有繪圖選項。
例子:
import matplotlib as plt
import numpy as np
class parentclass():
def __init__(self):
#functions to read some data
data=np.arange(100)
def plotaline(self,customargument1,customargument2,**kwargs):
cmin=customargument1*2
cmax=customargument2*4
#these are just for the sake of having other arguments
plt.plot(self.data,vmin=cmin,vmax=vmax,**kwargs)
# expected:
mydata=parentclass()
#plots a data line with red crosses as it takes the args that usually would go into plt.plot()
mydata.plotaline(0,1,'r- ')
我知道有些東西不見了。我需要一種將“繪圖”方法從 plt 庫傳遞給我的類方法的方法。也許這是我在這里遺漏的一些邏輯,當然我可能對繼承知之甚少。
幫助將不勝感激。
uj5u.com熱心網友回復:
添加*args并**kwargs包括可選的位置引數和關鍵字引數。
def plotaline(self,customargument1,customargument2, *args, **kwargs):
cmin=customargument1*2
cmax=customargument2*4
#these are just for the sake of having other arguments
plt.plot(self.data,vmin=cmin,vmax=vmax, *args, **kwargs)
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/430382.html
標籤:Python matplotlib 遗产
上一篇:為什么SocketIo如何使用mutableList更新我的UIJetpack?
下一篇:介面擴展是否等同于繼承?(爪哇)
