diff --git a/src/yapsut/AppendableDict.py b/src/yapsut/AppendableDict.py index e8ebb94d379781996b798d0e64d71dbd81e4a3b3..a54e596f3bc13fb0cdf182ca978beda490f90884 100644 --- a/src/yapsut/AppendableDict.py +++ b/src/yapsut/AppendableDict.py @@ -7,19 +7,15 @@ import time class AppendableDict : """ a dictionary, whose arguments are lists which can be appended - Example: - >AD=AppendableDict() - > - >AD['line1']=1 - >AD['line2']=10 - > - >AD['line1']=2 - >AD['line2']=20 - > - >AD['line1']=3 - >AD['line2']=30 - > - >print(AD['line1']) + Examples: + >>>AD=AppendableDict() + >>>AD['line1']=1 + >>>AD['line2']=10 + >>>AD['line1']=2 + >>>AD['line2']=20 + >>>AD['line1']=3 + >>>AD['line2']=30 + >>>print(AD['line1']) [1,2,3] """ diff --git a/src/yapsut/graphics.py b/src/yapsut/graphics.py index 79510c3b767c3ded14b22fd12836981f13f90f69..988a6e9f57a47401b97b450e46875f8f57781085 100644 --- a/src/yapsut/graphics.py +++ b/src/yapsut/graphics.py @@ -204,7 +204,34 @@ class StandardFig() : def split_path_setter(self,this) : self._split_path=(this==True) # + @property + def fig(self) : + """ handle for fig """ + try : + return self._handle['fig'] + except : + return None + # + @property + def handle(self) : + """ dictionary of graphic objects handles """ + return self._handle + # def __init__(self,figpath=None,figside=16,figratio=2/3,Creator='', Copyright='',Author='',split_path=False) : + """ + Creates a StandardFig object + + :Keywords: + figpath = path for the figure (None) + figside = horizontal side of the figure [in] (16) + figratio = V/H ratio of figure (2/3) + split_path = if True the path is splitted (False) + Creator = creator + Author = Author Name + Copyright = copyright string + + To have the handles to the figure components use the .handle dictionary. + """ self.free_metadata() # self._activated=True @@ -225,13 +252,17 @@ class StandardFig() : self.Creator=Creator self.Copyright=Copyright # - self.fig=None + # list of handles for various objects + self._handle={} # self.fontsize_ticks=16 self.fontsize_labels=18 self.fontsize_xylabels=18 self.fontsize_title=18 self.fontsize_legend=18 + self.fontsize_legend_title=18 + # + self.legend_framealpha=None def copy(self) : import copy return self.deepcopy(self) @@ -239,34 +270,56 @@ class StandardFig() : return self.new(squared=squared) def new(self,squared=False) : from matplotlib import pyplot as plt + self._handle={} if squared : - self.fig=plt.figure(figsize=(self.figside,self.figside)); + self._handle['fig']=plt.figure(figsize=(self.figside,self.figside)); else : - self.fig=plt.figure(figsize=self.figsize); + self._handle['fig']=plt.figure(figsize=self.figsize); self.fig.canvas.toolbar_visible = True self.fig.canvas.header_visible = False self.fig.canvas.resizable = True return self.fig - def legend(self,ncol=1,loc=1,title='',fontsize=None) : + def legend(self,ncol=1,loc=1,title='',fontsize=None,ax=None,title_fontsize=None,LISTP=None,legend_framealpha=None) : from matplotlib import pyplot as plt - fs=self.fontsize_legend if fontsize is None else fontsize - return plt.legend(ncol=ncol,loc=loc,fontsize=fs,title=title) + fsl=self.fontsize_legend if fontsize is None else fontsize + fslt=self.fontsize_legend_title if title_fontsize is None else title_fontsize + falpha=self.legend_framealpha if legend_framealpha is None else legend_framealpha + self.ax_legend=None + ax1=plt.gca() if ax==None else ax + # + if LISTP==None : + self._handle['legend']=ax1.legend(ncol=ncol,loc=loc,fontsize=fsl,title=title,title_fontsize=fslt) + return self._handle['legend'] + # + lns = LISTP[0] + for ik in range(len(LISTP)) : + if ik == 0 : + lns=LISTP[0] + else : + lns += LISTP[ik] + labs = [l.get_label() for l in lns] + self._handle['legend']=ax1.legend(lns, labs,ncol=ncol,loc=loc,fontsize=self.fontsize_legend if fontsize is None else fontsize,title=title,title_fontsize=fslt) + return self._handle['legend'] def title(self,txt,fontsize=None) : from matplotlib import pyplot as plt fs=self.fontsize_title if fontsize is None else fontsize - return plt.title(txt,fontsize=fs) + self._handle['title']=plt.title(txt,fontsize=fs) + return self._handle['title'] def suptitle(self,txt,fontsize=None) : from matplotlib import pyplot as plt fs=self.fontsize_title if fontsize is None else fontsize - return plt.suptitle(txt,fontsize=fs) + self._handle['suptitle']=plt.suptitle(txt,fontsize=fs) + return self._handle['suptitle'] def xlabel(self,txt,fontsize=None) : from matplotlib import pyplot as plt fs=self.fontsize_xylabels if fontsize is None else fontsize - return plt.xlabel(txt,fontsize=fs) + self._handle['xlabel']=plt.xlabel(txt,fontsize=fs) + return self._handle['xlabel'] def ylabel(self,txt,fontsize=None) : from matplotlib import pyplot as plt fs=self.fontsize_xylabels if fontsize is None else fontsize - return plt.ylabel(txt,fontsize=fs) + self._handle['ylabel']=plt.ylabel(txt,fontsize=fs) + return self._handle['ylabel'] def XTICKS(self,ax=None,fontsize=None) : from matplotlib import pyplot as plt fs=self.fontsize_ticks if fontsize is None else fontsize