def fakebaraxis(ticks, painter=fakebarpainter(), *args, **kwargs): """Return a PyX linear axis that can be used to make fake bar plots. Use "keyticks" to create the ticks expected by this function.""" return axis.linear(min=-0.75, max=len(ticks) - 0.25, parter=None, manualticks=ticks, painter=painter, *args, **kwargs)
print len(t) print "Recovered time shift = ", recovered_time_shift print "Recovered phase shift: %.2f pi" % (recovered_phase_shift/pi) pyplot.plot(t, ) pyplot.show() quit() from pyx import canvas, graph, text, color, style, trafo, unit from pyx.graph import axis, key text.set(mode="latex") text.preamble(r"\usepackage{txfonts}") figwidth = 12 gkey = key.key(pos=None, hpos=0.05, vpos=0.8) xaxis = axis.linear(title=r"Time, \(t\)") yaxis = axis.linear(title="Signal", min=-5, max=17) g = graph.graphxy(width=figwidth, x=xaxis, y=yaxis, key=gkey) plotdata = [graph.data.values(x=t, y=signal+offset, title=label) for label, signal, offset in (r"\(A(t) = \mathrm{square}(2\pi t/T)\)", A, 2.5), (r"\(B(t) = \mathrm{sawtooth}(\phi + 2 \pi t/T)\)", B, -2.5)] linestyles = [style.linestyle.solid, style.linejoin.round, style.linewidth.Thick, color.gradient.Rainbow, color.transparency(0.5)] plotstyles = [graph.style.line(linestyles)] g.plot(plotdata, plotstyles) g.plot(graph.data.values(x=t, y=listX, title="Blah"), plotstyles) g.text(10*unit.x_pt, 0.56*figwidth, r"\textbf{Cross correlation of noisy anharmonic signals}") g.text(10*unit.x_pt, 0.33*figwidth, "Phase shift: input \(\phi = %.2f \,\pi\), recovered \(\phi = %.2f \,\pi\)" % (phase_shift/pi, recovered_phase_shift/pi)) xxaxis = axis.linear(title=r"Time Lag, \(\Delta t\)", min=-1.5, max=1.5) yyaxis = axis.linear(title=r"\(A(t) \star B(t)\)") gg = graph.graphxy(width=0.2*figwidth, x=xxaxis, y=yyaxis) plotstyles = [graph.style.line(linestyles + [color.rgb(0.2,0.5,0.2)])] #gg.plot(graph.data.values(x=dt, y=xcorr), plotstyles) gg.plot(graph.data.values(x=dt, y=xcorr, title="Blah"), plotstyles)
import math from pyx import * from pyx.graph import axis texter1 = axis.texter.decimal(plus="+", minus="-", equalprecision=1) texter2 = axis.texter.rational() class piaxis(axis.linear): def __init__(self, divisor=math.pi, texter=axis.texter.rational(suffix="\pi"), **kwargs): axis.linear.__init__(self, divisor=divisor, texter=texter, **kwargs) p1 = path.path(path.moveto(0, 0), path.curveto(3, 0, 1, 4, 4, 4)) p2 = p1.transformed(trafo.translate(4, 0)) p3 = p2.transformed(trafo.translate(4, 0)) p4 = p3.transformed(trafo.translate(4, 0)) c = canvas.canvas() c.insert(axis.pathaxis(p1, axis.linear(min=0, max=1e2))) c.insert(axis.pathaxis(p2, axis.linear(min=-0.7, max=0.4, texter=texter1))) c.insert(axis.pathaxis(p3, axis.linear(min=-0.7, max=0.4, texter=texter2))) c.insert(axis.pathaxis(p4, piaxis(min=0, max=2 * math.pi))) c.writeEPSfile("texter") c.writePDFfile("texter") c.writeSVGfile("texter")
def emptyaxis(): """Return a PyX linear axis with no ticks""" return axis.linear(min=0, max=1, parter=None)
import math from pyx import * from pyx.graph import axis texter1 = axis.texter.decimal(plus="+", minus="-", equalprecision=1) texter2 = axis.texter.rational() class piaxis(axis.linear): def __init__(self, divisor=math.pi, texter=axis.texter.rational(suffix="\pi"), **kwargs): axis.linear.__init__(self, divisor=divisor, texter=texter, **kwargs) p1 = path.path(path.moveto(0, 0), path.curveto(3, 0, 1, 4, 4, 4)) p2 = p1.transformed(trafo.translate(4, 0)) p3 = p2.transformed(trafo.translate(4, 0)) p4 = p3.transformed(trafo.translate(4, 0)) c = canvas.canvas() c.insert(axis.pathaxis(p1, axis.linear(min=0, max=1e2))) c.insert(axis.pathaxis(p2, axis.linear(min=-0.7, max=0.4, texter=texter1))) c.insert(axis.pathaxis(p3, axis.linear(min=-0.7, max=0.4, texter=texter2))) c.insert(axis.pathaxis(p4, piaxis(min=0, max=2*math.pi))) c.writeEPSfile("texter") c.writePDFfile("texter")
from pyxcandy import read_dat, ssdata, ssplot text.set(cls=text.LatexRunner, texenc='utf-8') text.preamble(r'\usepackage[utf8]{inputenc}') text.preamble(r'\usepackage{textgreek}') text.preamble(r'\usepackage{fixltx2e}') text.preamble(r'\usepackage{libertine}') text.preamble(r'\renewcommand{\familydefault}{\sfdefault}') text.preamble(r'\usepackage{sansmath}') g = graph.graphxy( width=5.0, height=1.2, x=axis.linear(min=1, max=269, texter=texter.decimal(labelattrs=[text.clearmathmode]), title="TN residue"), y=axis.linear(min=0.0, parter=parter.linear(tickdists=[4.0, 2.0]), max=8.0, texter=texter.decimal(labelattrs=[text.clearmathmode]), title=r"RMSF ± std (Å)")) resid, rmsf_mean, rmsf_std = read_dat("rmsf.dat", [int, float, float]) g.plot(data.values(x=resid, y=rmsf_mean), [graph.style.line()]) ss = [line.strip() for line in open("ss.dat")] ssplot(g, ssdata(ss))
from math import pi from pyx import * from pyx.graph.axis import linear from pyx.graph.axis.texter import rational g = graph.graphxy(width=8, key=graph.key.key(pos="bl"), x=linear(min=0, max=2 * pi, title="$x$", divisor=pi, texter=rational(suffix=r"\pi")), y=linear(title="$y$")) g.plot(graph.data.function("y(x)=sin(x)", title=r"$\sin(x)$")) g.plot(graph.data.function("y(x)=cos(x)", title=r"$\cos(x)$")) g.writeEPSfile("piaxis")
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]
range = 2.5 p = painter.regular(basepathattrs=[earrow.normal], titlepos=0.95, outerticklength=painter.ticklength.normal, titledist=-0.3, titledirection=None) # horizontal text g = graphxy( width=10, xaxisat=0, yaxisat=0, x=axis.linear( title="$x$", min=-range, max=+range, painter=p, # suppress some ticks by overwriting ... manualticks=[tick.tick(0, None, None), tick.tick(range, None, None)]), y=axis.linear( title=r"$x\sin(x^2)$", painter=p, manualticks=[tick.tick(0, None, None), tick.tick(3, None, None)])) g.plot( data.function("y(x)=x*sin(x**2)"), # Line style is set before symbol style -> symbols will be draw # above the line. [ graph.style.line([style.linewidth.Thin, style.linestyle.solid]),
from math import pi from pyx import * from pyx.graph import axis g = graph.graphxy(width=8, key=graph.key.key(pos="bl"), x=axis.linear(min=0, max=2*pi, title="$x$", divisor=pi, texter=axis.texter.rational(suffix=r"\pi")), y=axis.linear(title="$y$")) g.plot(graph.data.function("y(x)=sin(x)", title=r"$\sin(x)$")) g.plot(graph.data.function("y(x)=cos(x)", title=r"$\cos(x)$")) g.finish() g.stroke(g.ygridpath(0)) g.writeEPSfile("piaxis") g.writePDFfile("piaxis")
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)
from math import pi, cos from pyx import * from pyx.deco import barrow, earrow from pyx.style import linewidth, linestyle from pyx.graph import graphxy from pyx.graph.axis import linear from pyx.graph.axis.painter import regular from pyx.graph.style import line from pyx.graph.data import function mypainter = regular(basepathattrs=[earrow.normal], titlepos=1) def mycos(x): return -cos(x)+.10*x g = graphxy(height=5, x2=None, y2=None, x=linear(min=-2.5*pi, max=3.3*pi, parter=None, painter=mypainter, title=r"$\delta\phi$"), y=linear(min=-2.3, max=2, painter=None)) g.plot(function("y(x)=mycos(x)", context=locals()), [line(lineattrs=[linewidth.Thick])]) g.finish() x1, y1 = g.pos(-pi+.1, mycos(-pi+.1)) x2, y2 = g.pos(-.1, mycos(-.1)) x3, y3 = g.pos(pi+.1, mycos(pi+.1)) g.stroke(path.line(x1-.5, y1, x1+.5, y1), [linestyle.dashed]) g.stroke(path.line(x1-.5, y3, x3+.5, y3), [linestyle.dashed]) g.stroke(path.line(x2-.5, y2, x3+.5, y2), [linestyle.dashed]) g.stroke(path.line(x1, y1, x1, y3), [barrow.normal, earrow.normal]) g.stroke(path.line(x3, y2, x3, y3), [barrow.normal, earrow.normal]) g.text(x1+.2, 0.5*(y1+y3), r"$2\pi\gamma k\Omega$", [text.vshift.middlezero])
titleattrs=[text.halign.right]) painter_y = painter.regular(basepathattrs=[deco.earrow], titlepos=1.03, titledist=0.15, titleattrs=[text.valign.top], titledirection=None) g1 = c.insert( graphxy(width=5, height=2, xaxisat=0, yaxisat=0, x=axis.linear(title="$x$", min=0, max=xrange, painter=painter_x, parter=None), y=axis.linear(title=r"$I(x)$", max=1.2, painter=painter_y, parter=None))) x2 = np.linspace(0, (0.93 * xrange)**2, 800) factor = sqrt(0.5 * pi) _, integral = fresnel(np.sqrt(x2) / factor) integral = factor * integral g1.plot(data.points(list(zip(np.sqrt(x2), integral)), x=1, y=2), lineproperties) g2 = c.insert(
# contributed by Francisco Borges from pyx import * from pyx.graph import graphxy, data, axis from pyx.graph.axis import painter, tick from pyx.deco import earrow range = 2.5 p = painter.regular(basepathattrs=[earrow.normal], titlepos=0.95, outerticklength=painter.ticklength.normal, titledist=-0.3, titledirection=None) # horizontal text g = graphxy(width=10, xaxisat=0, yaxisat=0, x=axis.linear(title="$x$", min=-range, max=+range, painter=p, # suppress some ticks by overwriting ... manualticks=[tick.tick(0, None, None), tick.tick(range, None, None)]), y=axis.linear(title=r"$x\sin(x^2)$", painter=p, manualticks=[tick.tick(0, None, None), tick.tick(3, None, None)])) g.plot(data.function("y(x)=x*sin(x**2)"), # Line style is set before symbol style -> symbols will be draw # above the line. [graph.style.line([style.linewidth.Thin, style.linestyle.solid]), graph.style.symbol(graph.style.symbol.circle, size=0.1, symbolattrs=[deco.filled([color.rgb.green]), deco.stroked([color.rgb.red])])]) # manually typeset "0" near the origin g.dolayout()
text.preamble(r'\usepackage[utf8]{inputenc}') text.preamble(r'\usepackage{textgreek}') text.preamble(r'\usepackage{fixltx2e}') text.preamble(r'\usepackage{libertine}') text.preamble(r'\renewcommand{\familydefault}{\sfdefault}') text.preamble(r'\usepackage{sansmath}') g = graphxy( width=5.0, height=2.4, x=fakebaraxis(ticks=protein_keys, texter=texter.decimal(labelattrs=[text.clearmathmode])), x2=emptyaxis(), y=axis.linear(min=0.0, max=12.0, parter=parter.linear(tickdists=[4.0, 2.0]), texter=texter.decimal(labelattrs=[text.clearmathmode]), title=r"C\textsubscript{α} RMSD ± std (Å)")) i = 0 time, rmsd = read_dat("rmsd_Ahc.xvg", [float, float]) rmsd = [x * 10 for x in rmsd] cloudplot(g, i, clouddata(rmsd), BlueU, ya=True) boxplot(g, i, boxdata(rmsd), ya=True) i = 1 time, rmsd = read_dat("rmsd_B2m.xvg", [float, float]) rmsd = [x * 10 for x in rmsd] cloudplot(g, i, clouddata(rmsd), DarkBlueD, ya=True) boxplot(g, i, boxdata(rmsd), ya=True)