Changeset 693


Ignore:
Timestamp:
09/29/05 16:35:59 (19 years ago)
Author:
mar637
Message:

added user customisable color and linestyles

Location:
branches/Release-2-fixes/python
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/Release-2-fixes/python/asaplot.py

    r671 r693  
    1717from matplotlib.numerix import sqrt
    1818from matplotlib import rc, rcParams
     19from asap import rcParams as asaprcParams
    1920
    2021# Force use of the newfangled toolbar.
     
    5859            self.set_panels(rows, cols)
    5960
    60 
    61         # Set matplotlib default colour sequence.
    62         self.colormap = ['blue', 'green', 'red', 'cyan', 'magenta', 'yellow', 'black', 'purple', 'orange', 'pink']
     61        # Set matplotlib default colour sequence.
     62        self.colormap = "green red black cyan magenta orange blue purple yellow pink".split()
     63       
     64        c = asaprcParams['plotter.colours']
     65        if isinstance(c,str) and len(c) > 0:
     66            self.colormap = c.split()
     67
     68        self.lsalias = {"line":  [1,0],
     69                        "dashdot": [4,2,1,2],
     70                        "dashed" : [4,2,4,2],
     71                        "dotted" : [1,2],
     72                        "dashdotdot": [4,2,1,2,1,2],
     73                        "dashdashdot": [4,2,4,2,1,2]
     74                        }
     75
     76        styles = "line dashed dotted dashdot".split()
     77        c = asaprcParams['plotter.linestyles']
     78        if isinstance(c,str) and len(c) > 0:
     79            styles = c.split()
     80        s = []
     81        for ls in styles:
     82            if self.lsalias.has_key(ls):
     83                s.append(self.lsalias.get(ls))
     84            else:
     85                s.append('-')
     86        self.linestyles = s
     87
    6388        self.color = 0;
     89        self.linestyle = 0;
    6490        self.attributes = {}
    6591        self.loc = 0
     
    80106        self.axes.clear()
    81107        self.color = 0
     108        self.linestyle = 0
    82109        self.lines = []
    83110
    84 
    85     def palette(self, color, colormap=None):
     111    def palette(self, color, colormap=None, linestyle=0, linestyles=None):
    86112        if colormap:
    87             self.colormap = colormap
     113            if isinstance(colormap,list):
     114                self.colormap = colormap
     115            elif isinstance(colormap,str):
     116                self.colormap = colormap.split()
    88117        if 0 <= color < len(self.colormap):
    89118            self.color = color
     119        if linestyles:
     120            self.linestyles = []
     121            if isinstance(linestyles,list):
     122                styles = linestyles
     123            elif isinstance(linestyles,str):
     124                styles = linestyles.split()
     125            for ls in styles:
     126                if self.lsalias.has_key(ls):
     127                    self.linestyles.append(self.lsalias.get(ls))
     128                else:
     129                    self.linestyles.append(self.lsalias.get('line'))
     130        if 0 <= linestyle < len(self.linestyles):
     131            self.linestyle = linestyle
    90132
    91133    def delete(self, numbers=None):
     
    244286            for segment in self.lines[i]:
    245287                getattr(segment, "set_color")(self.colormap[self.color])
    246 
     288                if len(self.colormap)  == 1:
     289                    getattr(segment, "set_dashes")(self.linestyles[self.linestyle])
    247290            self.color += 1
    248291            if self.color >= len(self.colormap):
    249292                self.color = 0
     293
     294            if len(self.colormap) == 1:
     295                self.linestyle += 1
     296            if self.linestyle >= len(self.linestyles):
     297                self.linestyle = 0               
    250298
    251299        self.show()
  • branches/Release-2-fixes/python/asapplotter.py

    r672 r693  
    193193               
    194194                xlim=[min(x),max(x)]
     195                if self._minmaxx is not None:
     196                    xlim = self._minmaxx
    195197                self._plotter.axes.set_xlim(xlim)
    196198            self._plotter.set_axes('xlabel',xlab)
     
    200202
    201203    def _plot_scans(self, scans, colmode):
    202         print "Can only plot one row per scan."
     204        print "Plotting mode is scans across panels. Can only plot one row per scan."
    203205        if colmode == 's':
    204206            return
     
    285287                self._plotter.plot(x,y,m)
    286288                xlim=[min(x),max(x)]
     289                if self._minmaxx is not None:
     290                    xlim = self._minmaxx
    287291                self._plotter.axes.set_xlim(xlim)
    288292
     
    410414                self._plotter.plot(x,y,m)
    411415                xlim=[min(x),max(x)]
     416                if self._minmaxx is not None:
     417                    xlim = self._minmaxx
    412418                self._plotter.axes.set_xlim(xlim)
    413419
     
    424430        Parameters:
    425431            stacking:     tell the plotter which variable to plot
    426                           as line colour overlays (default 'pol')
     432                          as line color overlays (default 'pol')
    427433            panelling:    tell the plotter which variable to plot
    428434                          across multiple panels (default 'scan'
     
    510516             mp:    a list of 'strings'. This should have the same length
    511517                    as the number of elements on the legend and then maps
    512                     to the indeces in order
     518                    to the indeces in order. It is possible to uses latex
     519                    math expression. These have to be enclosed in r'', e.g. r'$x^{2}$'
    513520
    514521        Example:
     
    516523             for CO and SiO:
    517524             plotter.set_stacking('i')
    518              plotter.set_legend_map(['CO','SiO'])
     525             plotter.set_legend(['CO','SiO'])
    519526             plotter.plot()
     527             plotter.set_legend([r'$^{12}CO$', r'SiO'])
    520528        """
    521529        self._lmap = mp
     
    524532
    525533    def set_title(self, title=None):
     534        """
     535        Set the title of the plot. If multiple panels are plotted,
     536        multiple titles have to be specified.
     537        Example:
     538             # two panels are visible on the plotter
     539             plotter.set_title(["First Panel","Second Panel"])
     540        """
    526541        self._title = title
    527542        if self._data: self.plot()
     
    529544
    530545    def set_ordinate(self, ordinate=None):
     546        """
     547        Set the y-axis label of the plot. If multiple panels are plotted,
     548        multiple labels have to be specified.
     549        Example:
     550             # two panels are visible on the plotter
     551             plotter.set_ordinate(["First Y-Axis","Second Y-Axis"])
     552        """
    531553        self._ordinate = ordinate
    532554        if self._data: self.plot()
     
    534556
    535557    def set_abcissa(self, abcissa=None):
     558        """
     559        Set the x-axis label of the plot. If multiple panels are plotted,
     560        multiple labels have to be specified.
     561        Example:
     562             # two panels are visible on the plotter
     563             plotter.set_ordinate(["First X-Axis","Second X-Axis"])
     564        """
    536565        self._abcissa = abcissa
    537566        if self._data: self.plot()
    538567        return
    539568
     569    def set_colors(self, colormap):
     570        """
     571        Set the colors to be used. The plotter will cycle through
     572        these colors when lines are overlaid (stacking mode).
     573        Example:
     574             plotter.set_colors("red green blue")
     575             # If for example four lines are overlaid e.g I Q U V
     576             # 'I' will be 'red', 'Q' will be 'green', U will be 'blue'
     577             # and 'V' will be 'red' again.
     578        """
     579        self._plotter.palette(0,colormap=colormap)
     580        if self._data: self.plot()
     581
     582    def set_linestyles(self, linestyles):
     583        """
     584        Parameters:
     585             linestyles:     a list of linestyles to use.
     586                             'line', 'dashed', 'dotted', 'dashdot',
     587                             'dashdotdot' and 'dashdashdot' are
     588                             possible
     589                             
     590        Set the linestyles to be used. The plotter will cycle through
     591        these linestyles when lines are overlaid (stacking mode) AND
     592        only one color has been set.
     593        Example:
     594             plotter.set_colors("black")
     595             plotter.set_linestyles("line dashed dotted dashdot")
     596             # If for example four lines are overlaid e.g I Q U V
     597             # 'I' will be 'solid', 'Q' will be 'dashed',
     598             # U will be 'dotted' and 'V' will be 'dashdot'.
     599        """
     600        self._plotter.palette(color=0,linestyle=0,linestyles=linestyles)
     601        if self._data: self.plot()
     602   
    540603    def save(self, filename=None, orientation=None):
    541604        """
     
    619682        dstokes2 = {"I":0,"Plinear":1,"Pangle":2,"V":3}
    620683        draw = {"XX":0, "YY":1,"Real(XY)":2, "Imag(XY)":3}
    621         dcirc = { "RR":0,"LL":1}#,"Real(RL)":2,"Image(RL)":3}
     684        dcirc = { "RR":0,"LL":1}#,"Real(RL)":2,"Imag(RL)":3}
    622685       
    623686        if pol is None:
Note: See TracChangeset for help on using the changeset viewer.