Beispiel #1
0
def test_log():
    import numpy
    from numpy import log10
    x=numpy.logspace(log10(0.1), log10(30.0), 10)
    y=1.0/x

    # we here use parters and texters which are explained in the examples below
    #log2parter = axis.parter.log([axis.parter.preexp([axis.tick.rational(1)], 4),
    #                              axis.parter.preexp([axis.tick.rational(1)], 2)])
    #log2texter = axis.texter.exponential(nomantissaexp=r"{2^{%s}}",
    #                                     mantissamax=axis.tick.rational(2))

    fac=2.0
    g = graph.graphxy(
        width=8,
        height=8,
        #ratio=1.0,
        x=axis.log(min=x.min()/fac,max=fac*x.max(),title=r'$R~ [h^{-1}$ Mpc]'),
        y=axis.log(min=y.min()/fac,max=fac*y.max(),title=r'$\Delta\Sigma ~[h~$M$_\odot~$pc$^{-2}]$'),
    )

    symbol=graph.style.symbol(
        symbol=graph.style._circlesymbol,
        size=0.1,
        symbolattrs=[deco.filled([color.rgb.black])],
    )

    values=graph.data.values(x=list(x),y=list(y))
    g.plot(values,[symbol])

    #g.writeEPSfile("log")
    #g.writePDFfile("log")
    g.writetofile("log-test.pdf")
    g.writetofile("log-test.eps")
Beispiel #2
0
def plot_c2rng():
    #nocorr     = [1.78, 1.16, 0.46]
    #err_nocorr = [0.27, 0.18, 0.12]

    #corr       = [0.27, 0.09, 0.20]
    #err_corr   = [0.27, 0.18, 0.12]

    nocorr=array([1.702e-04,
                  7.042e-05,
                  4.098e-06,
                  8.133e-05])/1.0e-4

    err_nocorr=array([1.899e-05,
                      1.662e-05,
                      1.849e-05,
                      2.582e-05])/1.0e-4

    corr=array([2.279e-05,
                2.110e-05,
                -1.680e-05,
                6.090e-05])/1.0e-4

    err_corr=array([1.891e-05,
                    1.654e-05,
                    1.849e-05,
                    2.588e-05])/1.0e-4

    ymin,ymax=-3,3
    xlabel=r'$\langle S/N \rangle$'
    xaxis=axis.log(min=log_xrng[0],max=log_xrng[1],title=xlabel)

    c,g=plot_c(s2n_means,corr,err_corr,nocorr,err_nocorr,ymin,ymax,xaxis)
    return c,g
Beispiel #3
0
def _get_axes(kw):
    xlog=kw.get('xlog',False)
    ylog=kw.get('ylog',False)

    xkw=dict(
        title=kw.get('xlabel',None),

        min=kw.get('xmin',None),
        max=kw.get('xmax',None),

        # density of ticks
        density=kw.get('xdensity',1),
        reverse=kw.get('xreverse',0),
    )
    ykw=dict(
        title=kw.get('ylabel',None),

        min=kw.get('ymin',None),
        max=kw.get('ymax',None),

        # density of ticks
        density=kw.get('ydensity',1),
        reverse=kw.get('yreverse',0),
    )

    if xlog:
        xaxis = axis.log(**xkw)
    else:
        xaxis = axis.lin(**xkw)

    if ylog:
        yaxis = axis.log(**ykw)
    else:
        yaxis = axis.lin(**ykw)

    return xaxis, xlog, yaxis, ylog
Beispiel #4
0
import math
from pyx import *
from pyx.graph import axis

# we here use parters and texters which are explained in the examples below
log2parter = axis.parter.log([
    axis.parter.preexp([axis.tick.rational(1)], 4),
    axis.parter.preexp([axis.tick.rational(1)], 2)
])
log2texter = axis.texter.exponential(nomantissaexp=r"{2^{%s}}",
                                     mantissamax=axis.tick.rational(2))

g = graph.graphxy(width=10,
                  x=axis.log(min=1, max=1024),
                  y=axis.log(min=1, max=1024, parter=log2parter),
                  y2=axis.log(min=1,
                              max=1024,
                              parter=log2parter,
                              texter=log2texter))

g.writeEPSfile("log")
g.writePDFfile("log")
g.writeSVGfile("log")
Beispiel #5
0
    def __init__(self, args):
        narg = len(args)
        if nargs < 2:
            self.usage()
        self.out = 'plot'
        self.xlabel = None
        self.ylabel = None
        self.xmin = None
        self.xmax = None
        self.ymin = None
        self.ymax = None
        self.key = None
        self.width = 8
        self.height = 5
        self.kdist = 0.1
        self.xlog = 0
        self.ylog = 0

        keyz = ''
        future_plots = []
        current_args = []
        keep = 0
        has_name = 0

        # we iterate through arguments and assign them to global or local options
        for arg in args:
            # Global options
            if arg.startswith('out='):
                self.out = arg[4:]
            elif arg.startswith('xlabel='):
                self.xlabel = arg[7:]
            elif arg.startswith('ylabel='):
                self.ylabel = arg[7:]
            elif arg.startswith('width='):
                self.width = float(arg[6:])
            elif arg.startswith('height='):
                self.height = float(arg[7:])
            elif arg.startswith('xmin='):
                self.xmin = float(arg[5:])
            elif arg.startswith('ymin='):
                self.ymin = float(arg[5:])
            elif arg.startswith('xmax='):
                self.xmax = float(arg[5:])
            elif arg.startswith('ymax='):
                self.ymax = float(arg[5:])
            elif arg.startswith('key='):
                keyz = arg[4:]
            elif arg.startswith('kdist='):
                self.kdist = arg[6:]
            elif arg.startswith('legend=') or arg.startswith('title'):
                self.key = graph.key.key(pos="tl", dist=self.kdist)
            elif arg.startswith('--help'):
                self.usage()
            elif arg.startswith('-xlog'):
                self.xlog = 1
            elif arg.startswith('-ylog'):
                self.ylog = 1
            # Local / semi-local options
            elif arg.startswith('andif'):
                if has_name == 0:
                    raise ValueError(
                        'Error : cannot use andif= before the first declared file'
                    )
                else:
                    #future_plots.append(Toplot(fname,current_args))
                    current_args.append(__SPLIT_MARK__)
                    current_args.append(arg)

            elif arg.startswith('-keep'):
                keep = 1
            elif arg.startswith('-discard'):
                keep = 0
            elif arg.startswith('-') or arg.find('=') >= 0:
                current_args.append(arg)
            # If it's not an option, it's definitey a filename
            elif arg == 'and':
                current_args.append(__SPLIT_MARK__)
            else:
                # If there is already a name for a future plot
                if has_name:
                    future_plots.append(Toplot(fname, current_args))
                    if keep == 0:
                        current_args = []
                else:
                    has_name = 1
                fname = arg

        # We still need add the last file to futureèplots
        if has_name:
            future_plots.append(Toplot(fname, current_args))
            has_name = 0

        # we check if the plots must be split by and / andif
        for toplot in future_plots:
            [is_split, new_plot] = toplot.check_split()
            if is_split:
                future_plots.append(new_plot)

        # we deal with global plot properties
        if self.xlabel:
            try:
                self.xlabel = r"%s" % (self.xlabel)
            except:
                self.xlabel = None

        if self.ylabel:
            try:
                self.ylabel = r"%s" % (self.ylabel)
            except:
                self.ylabel = None

        try:
            self.key = graph.key.key(pos="%s" % (keyz), dist=float(self.kdist))
        except:
            if keyz == 'None':
                self.key = None

        if self.xlog:
            xaxis = axis.log(title=self.xlabel, min=self.xmin, max=self.xmax)
        else:
            xaxis = axis.linear(title=self.xlabel,
                                min=self.xmin,
                                max=self.xmax)
        if self.ylog:
            yaxis = axis.log(title=self.ylabel, min=self.ymin, max=self.ymax)
        else:
            yaxis = axis.linear(title=self.ylabel,
                                min=self.ymin,
                                max=self.ymax)

        self.graph = graph.graphxy(width=self.width,
                                   height=self.height,
                                   key=self.key,
                                   x=xaxis,
                                   y=yaxis)

        # We create the graphs
        self.graphs = [Graph(toplot) for toplot in future_plots]
Beispiel #6
0
    def make_plot(self, *args, **kwargs):
        self.read_args(*args, **kwargs)
        # we check if the plots must be split by and / andif
        for i, toplot in enumerate(self.future_plots):
            [is_split, new_plot] = toplot.check_split()
            if is_split:
                #print('splitting  ******************************')
                self.future_plots.append(new_plot)

        ## Now we create the graphs
        # We create the graphs
        #self.graphs=[Graph(toplot) for toplot in self.future_plots]
        for i, toplot in enumerate(self.future_plots):
            (args, kwargs) = toplot.unpack_arguments()
            kwargs['numr'] = i
            self.graphs.append(Graph(*args, **kwargs))

            #print(i)
        #self.graphs=[Graph(toplot) for toplot in self.future_plots]
        if self.autolabel:
            for graf in self.graphs:
                if graf.xlabel:
                    if not self.xlabel:
                        self.xlabel = graf.xlabel
                if graf.ylabel:
                    if not self.ylabel:
                        self.ylabel = graf.ylabel

        # we deal with global plot properties
        if self.xlabel:
            try:
                self.xlabel = r"%s" % (self.xlabel)
            except:
                self.xlabel = None

        if self.ylabel:
            try:
                self.ylabel = r"%s" % (self.ylabel)
            except:
                self.ylabel = None

        if self.equalaxis:
            self.height = self.width
            self.make_equal_axis_range()

        if self.xlog:
            xaxis = axis.log(title=self.xlabel, min=self.xmin, max=self.xmax)
            for graf in self.graphs:
                if sum(array(graf.X) <= 0):
                    raise ValueError(
                        'Could not plot log with non-positive X values')
        else:
            xaxis = axis.linear(title=self.xlabel,
                                min=self.xmin,
                                max=self.xmax)

        if self.ylog:
            yaxis = axis.log(title=self.ylabel, min=self.ymin, max=self.ymax)
            for graf in self.graphs:
                if sum(array(graf.Y) <= 0):
                    raise ValueError(
                        'Could not plot log with non-positive X values')
        else:
            yaxis = axis.linear(title=self.ylabel,
                                min=self.ymin,
                                max=self.ymax)

        self.graph = graph.graphxy(width=self.width,
                                   height=self.height,
                                   key=self.key,
                                   x=xaxis,
                                   y=yaxis)

        ## Here we do the plotting itlsef
        for graf in self.graphs:
            self.plot(graf)
        ## We finish() the graph to be able to work with pathes
        self.graph.finish()

        ## Now if there are graphs with a stroke_style, we paint them !
        # This is meant for histograms
        for graf in self.graphs:
            if len(graf.stroke_style):
                for plot in graf.ploted:
                    self.canvas.stroke(plot.path, graf.stroke_style)

        self.canvas.insert(self.graph)
Beispiel #7
0
import math
from pyx import *
from pyx.graph import axis

# we here use parters and texters which are explained in the examples below
log2parter = axis.parter.log(
    [axis.parter.preexp([axis.tick.rational(1)], 4), axis.parter.preexp([axis.tick.rational(1)], 2)]
)
log2texter = axis.texter.exponential(nomantissaexp=r"{2^{%s}}", mantissamax=axis.tick.rational(2))

g = graph.graphxy(
    width=10,
    x=axis.log(min=1, max=1024),
    y=axis.log(min=1, max=1024, parter=log2parter),
    y2=axis.log(min=1, max=1024, parter=log2parter, texter=log2texter),
)

g.writeEPSfile("log")
g.writePDFfile("log")
g.writeSVGfile("log")