Commit fa9da3a2 authored by Michele Maris's avatar Michele Maris
Browse files

u

parent 11b842d0
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ from .periodic_stats import periodic_stats, periodic_centroid
from .stats import CumulativeOfData
from .colored_noise import gaussian_colored_noise
from .montecarlo_fitting import EnsembleFitting_Base
from .bar_plots import multi_vertical_bars
#from .bars_collections import multi_vertical_bars
#from .collate_images import collate_images_r1_c2, collate_images_r2_c1, collate_images_r2_c2

# planck legacy is under editing
+86 −0
Original line number Diff line number Diff line
class multi_vertical_bars :
    """draws a set of vertical bars grouped"""
    @property
    def bar_fontsize(self) :
        """fontsize of bar"""
        return self._bar_fontsize
    @bar_fontsize.setter
    def bar_fontsize(self,this) :
        """fontsize of bar"""
        self._bar_fontsize=this

    @property
    def barborder(self) :
        """width of bar border"""
        return self._barborder
    @barborder.setter
    def barborder(self,this) :
        """width of bar border"""
        self._barborder=this
        
    @property
    def nbars(self) :
        """number of bars"""
        return self._nbars
        
    @property
    def bars(self) :
        return self._bs

    def __init__(self) :
        self.clear() 
        self._barborder=0.05
        self.reset()

    def __setitem__(self,this,that) :
        self.__dict__[f'_{this}']=that
        
    def __getitem__(self,this) :
        return self.__dict__[f'_{this}']
        
    def clear(self) :
        self._barborder=0.
        self._bs=None
        self._isbpl=-1
        self._nbars=0
        self._barwidth=0.
        self._barthick=0.
        self._barsx=None
        self._bar_fontsize=18
        
    def reset(self) :
        self._isbpl=0

    def set_bars(self,bd) :
        """bd is a dictionary of symbols: for name {color, title} """
        self._nbars=len(bd)
        self._barwidth=1-2*self._barborder
        self._barthick=self._barwidth/self._nbars
        xx=self._barwidth/2-self._barthick/2
        self._barsx=np.linspace(-xx,xx,self._nbars)
        self._bs={}
        for ik,k in enumerate(bd.keys()) :
            self._bs[k]={'ix':self._barsx[ik],'color':bd[k]['color'],'title':bd[k]['title']}

    def draw(self,name,ydict,put_bar_titles=True,put_bar_label=False) :
        self._isbpl+=1
        h=plt.plot(name,0,'-w')[0].set_visible(False)

        for ikk,kk in enumerate(ydict.keys()) :
            xx=self._bs[kk]['ix']+self._isbpl-1
            yy=ydict[kk]
            title=self._bs[kk]['title']
            color=self._bs[kk]['color']
            lbl=title if put_bar_label else None
            plt.bar( xx,yy,width=self._barthick,color=color,label=lbl)
            if put_bar_titles :
                plt.text(xx,yy,title,
                         fontsize=self._bar_fontsize,
                         rotation=90,
                         horizontalalignment='center',
                         verticalalignment='bottom'
                        )
        for k in plt.gca().get_xticklabels() :
            k.set_rotation(90)