Я думаю, что самым чистым решением для этого является создание «шаблона сюжета компании» в отдельном скрипте python (например, называемом companyplots.py
), который находится где-то в пути поиска модуля модуля *.
Вы можете сделать это либо просто поместив его в ту же папку, что и ваши реальные графики, либо, например, путем создания папки /some/path/to/user_modules
и правильной установки переменной $PYTHONPATH
для включения пути к ней.
В этом файле соберите все необходимые импорта и настройте функцию с настройками графика по умолчанию, например ::
.
def companyFigure((rows,cols),(width,height)=(768,576),dpi=72,fig_kwargs={}):
"""
first, reset mpl style to default, then enforce a new one.
This is helpful when the new style does not overwrite *all* attributes
"""
style="ggplot" ##<- put your own style file here, if you have one
mpl.rcParams.update(mpl.rcParamsDefault)
mpl.style.use(style)
## that's your function:
def add_watermark(ax):
ax.text(ax.get_xlim()[0] + 0.1,
ax.get_ylim()[0] + 0.1,
"<Company Name>",
alpha=0.5)
## create figure with some arguments
fig,ax=plt.subplots(rows,cols,
figsize=(width/float(dpi),height/float(dpi)),
dpi=dpi,
**fig_kwargs
)
## I'm presuming that you may want to have subplots somewhere down the line;
## for the sake of consistency, I'm thus making sure that "ax" is always a dict:
if rows==1 and cols==1:
ax={0:ax}
for a in ax:
add_watermark(a)
return fig,ax
Теперь все будущие графики могут вернуться к этому шаблону, просто запустив:
from companyplots import *
fig,ax=companyFigure((2,1),(500,300))
## do your plotting here...
plt.show()