def testDefault(self): ticks = [tick((0, 10), labellevel=0), tick((1, 10), labellevel=0), tick((1, 1), labellevel=0), tick((10, 1), labellevel=0)] mixed().labels(ticks) self.assertEqual([t.label for t in ticks], ["0", "0.1", "1", "10"]) ticks = [tick((0, 10), labellevel=0), tick((1, 10), labellevel=0), tick((1, 1), labellevel=0), tick((10000, 1), labellevel=0)] mixed().labels(ticks) self.assertEqual([t.label for t in ticks], [r"{0}", r"{{1}\cdot10^{-1}}", r"{1}", r"{{1}\cdot10^{4}}"]) ticks = [tick((0, 10), labellevel=0), tick((1, 10), labellevel=0), tick((1, 1), labellevel=0), tick((10000, 1), labellevel=0)] mixed(equaldecision=0).labels(ticks) self.assertEqual([t.label for t in ticks], ["0", "0.1", "1", r"{10^{4}}"])
def keyticks(labels, *args, **kwargs): """Return a list of PyX ticks that can be used as keys in a fake bar plot. Each key is assigned an integer position on the graph axis starting at 0.""" return [tick(i, label=labels[i], *args, **kwargs) \ for i in range(len(labels))]
def testDec(self): ticks = [tick((1, 4), labellevel=0), tick((2, 4), labellevel=0)] decimal().labels(ticks) self.assertEqual([t.label for t in ticks], ["0.25", "0.5"]) ticks = [tick((1, 4), labellevel=0), tick((2, 4), labellevel=0)] decimal(equalprecision=1).labels(ticks) self.assertEqual([t.label for t in ticks], ["0.25", "0.50"]) ticks = [tick((1, 17), labellevel=0), tick((17, 17), labellevel=0)] decimal().labels(ticks) self.assertEqual([t.label for t in ticks], [r"0.\overline{0588235294117647}", "1"]) ticks = [tick((1, 10000000), labellevel=0), tick((1, 100000000), labellevel=0), tick((1, 1000000000), labellevel=0)] decimal(thousandthpartsep=",").labels(ticks) self.assertEqual([t.label for t in ticks], ["0.000,000,1", "0.000,000,01", "0.000,000,001"]) ticks = [tick((1000000, 1), labellevel=0), tick((10000000, 1), labellevel=0), tick((100000000, 1), labellevel=0)] decimal(thousandsep=",").labels(ticks) self.assertEqual([t.label for t in ticks], ["1,000,000", "10,000,000", "100,000,000"])
def getticks(self, min, max, dist, ticklevel=None, labellevel=None): """return a list of equal spaced ticks - the tick distance is dist, the ticklevel is set to ticklevel and the labellevel is set to labellevel - min, max is the range where ticks should be placed""" imin = int(math.ceil(min/float(dist) - 0.5*self.epsilon)) imax = int(math.floor(max/float(dist) + 0.5*self.epsilon)) ticks = [] for i in range(imin, imax + 1): ticks.append(tick.tick((i*dist.num, dist.denom), ticklevel=ticklevel, labellevel=labellevel)) return ticks
def testFrac(self): ticks = [tick((1, 4), labellevel=0), tick((2, 4), labellevel=0)] rational(numsuffix=r"\pi").labels(ticks) self.assertEqual([tex_expr(t.label) for t in ticks], [r"{{\pi}\over{4}}", r"{{\pi}\over{2}}"]) ticks = [tick((0, 3), labellevel=0), tick((3, 3), labellevel=0), tick((6, 3), labellevel=0)] rational(numsuffix=r"\pi").labels(ticks) self.assertEqual([tex_expr(t.label) for t in ticks], ["0", r"\pi", r"2\pi"]) ticks = [tick((2, 3), labellevel=0), tick((4, 5), labellevel=0)] rational(numsuffix=r"\pi", equaldenom=1).labels(ticks) self.assertEqual([tex_expr(t.label) for t in ticks], [r"{{10\pi}\over{15}}", r"{{12\pi}\over{15}}"])
def testFrac(self): ticks = [tick((1, 4), labellevel=0), tick((2, 4), labellevel=0)] rational(numsuffix=r"\pi").labels(ticks) self.assertEqual([t.label for t in ticks], [r"{{\pi}\over{4}}", r"{{\pi}\over{2}}"]) ticks = [tick((0, 3), labellevel=0), tick((3, 3), labellevel=0), tick((6, 3), labellevel=0)] rational(numsuffix=r"\pi").labels(ticks) self.assertEqual([t.label for t in ticks], ["0", r"\pi", r"2\pi"]) ticks = [tick((2, 3), labellevel=0), tick((4, 5), labellevel=0)] rational(numsuffix=r"\pi", equaldenom=1).labels(ticks) self.assertEqual([t.label for t in ticks], [r"{{10\pi}\over{15}}", r"{{12\pi}\over{15}}"])
def testExp(self): ticks = [tick((-1, 10), labellevel=0), tick((1, 1), labellevel=0), tick((10, 1), labellevel=0)] exponential().labels(ticks) self.assertEqual([t.label for t in ticks], [r"{-10^{-1}}", r"{10^{0}}", r"{10^{1}}"]) ticks = [tick((0, 1), labellevel=0), tick((1, -10), labellevel=0), tick((15, 100), labellevel=0)] exponential(mantissatexter=decimal(equalprecision=1)).labels(ticks) self.assertEqual([t.label for t in ticks], [r"{0.0}", r"{{-1.0}\cdot10^{-1}}", r"{{1.5}\cdot10^{-1}}"])
def getticks(self, min, max, preexp, ticklevel=None, labellevel=None): ticks = [] minimin = 0 maximax = 0 for f in preexp.pres: thisticks = [] imin = int(math.ceil(math.log(min / float(f)) / math.log(preexp.exp) - 0.5 * self.epsilon)) imax = int(math.floor(math.log(max / float(f)) / math.log(preexp.exp) + 0.5 * self.epsilon)) for i in range(imin, imax + 1): pos = f * tick.rational((preexp.exp, 1), power=i) thisticks.append(tick.tick((pos.num, pos.denom), ticklevel = ticklevel, labellevel = labellevel)) ticks = tick.mergeticklists(ticks, thisticks) return ticks
titledirection=None, outerticklength=graph.axis.painter.ticklength.normal, ) g = graph.graphxy(width=8, xaxisat=0, yaxisat=0, x=graph.axis.linear(title="$t$", min=-2.9, max=2.9, painter=p), y=graph.axis.linear( min=-0.05, max=1.9, manualticks=[ tick.tick(0, None, None), tick.tick(0.5, label=r"$\frac{1}{2}$", ticklevel=0), tick.tick(1.5, label=r"$\frac{3}{2}$", ticklevel=0), ], painter=p)) def f(t, x): return t, sum([x[i] * (t**i) for i in range(len(x))]) g.plot( graph.data.paramfunction("t", -3,
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,
def testLogParter(self): self.PartEqual(log(tickpreexps=[log.pre1exp], labelpreexps=[]).partfunctions(1, 10, 1, 1)[0](), [tick((1, 1), 0, None), tick((10, 1), 0, None)]) self.PartEqual(log(tickpreexps=[log.pre1exp], labelpreexps=[]).partfunctions(1, 100, 1, 1)[0](), [tick((1, 1), 0, None), tick((10, 1), 0, None), tick((100, 1), 0, None)]) self.PartEqual(log(tickpreexps=[preexp([rational((1, 1))], 100)], labelpreexps=[]).partfunctions(1, 100, 1, 1)[0](), [tick((1, 1), 0, None), tick((100, 1), 0, None)]) self.PartEqual(log(tickpreexps=[log.pre1to9exp], labelpreexps=[]).partfunctions(1, 10, 1, 1)[0](), [tick((1, 1), 0, None), tick((2, 1), 0, None), tick((3, 1), 0, None), tick((4, 1), 0, None), tick((5, 1), 0, None), tick((6, 1), 0, None), tick((7, 1), 0, None), tick((8, 1), 0, None), tick((9, 1), 0, None), tick((10, 1), 0, None)]) self.PartEqual(log(tickpreexps=[log.pre1exp, log.pre1to9exp], labelpreexps=[]).partfunctions(1, 10, 1, 1)[0](), [tick((1, 1), 0, None), tick((2, 1), 1, None), tick((3, 1), 1, None), tick((4, 1), 1, None), tick((5, 1), 1, None), tick((6, 1), 1, None), tick((7, 1), 1, None), tick((8, 1), 1, None), tick((9, 1), 1, None), tick((10, 1), 0, None)]) self.PartEqual(log(tickpreexps=[log.pre1exp, log.pre1to9exp]).partfunctions(1, 10, 1, 1)[0](), [tick((1, 1), 0, 0), tick((2, 1), 1, None), tick((3, 1), 1, None), tick((4, 1), 1, None), tick((5, 1), 1, None), tick((6, 1), 1, None), tick((7, 1), 1, None), tick((8, 1), 1, None), tick((9, 1), 1, None), tick((10, 1), 0, 0)])
def testLinParter(self): self.PartEqual(lin(tickdists=["10"], labeldists=[]).partfunctions(0, 1, 1, 1)[0](), [tick((0, 1), 0, None), tick((10, 1), 0, None)]) self.PartEqual(lin(tickdists=["1", "0.5"], labeldists=[]).partfunctions(0, 1, 1, 1)[0](), [tick((0, 1), 0, None), tick((1, 2), 1, None), tick((1, 1), 0, None)]) self.PartEqual(lin(tickdists=["1", "0.5", "0.25"], labeldists=[]).partfunctions(0, 1, 1, 1)[0](), [tick((0, 1), 0, None), tick((1, 4), 2, None), tick((1, 2), 1, None), tick((3, 4), 2, None), tick((1, 1), 0, None)]) self.PartEqual(lin(tickdists=["1", "0.5"], labeldists=[], extendtick=None).partfunctions(0, 1.5, 1, 1)[0](), [tick((0, 1), 0, None), tick((1, 2), 1, None), tick((1, 1), 0, None), tick((3, 2), 1, None)]) self.PartEqual(lin(tickdists=["1", "0.5"], labeldists=[], extendtick=1).partfunctions(0, 1.2, 1, 1)[0](), [tick((0, 1), 0, None), tick((1, 2), 1, None), tick((1, 1), 0, None), tick((3, 2), 1, None)]) self.PartEqual(lin(tickdists=["1", "0.5"], labeldists=[], extendtick=0).partfunctions(0, 1.2, 1, 1)[0](), [tick((0, 1), 0, None), tick((1, 2), 1, None), tick((1, 1), 0, None), tick((3, 2), 1, None), tick((2, 1), 0, None)]) self.PartEqual(lin(labeldists=["1"], tickdists=[]).partfunctions(0, 1, 1, 1)[0](), [tick((0, 1), None, 0), tick((1, 1), None, 0)]) self.PartEqual(lin(labeldists=["1", "0.5"], tickdists=[]).partfunctions(0, 1, 1, 1)[0](), [tick((0, 1), None, 0), tick((1, 2), None, 1), tick((1, 1), None, 0)]) self.PartEqual(lin(labeldists=["1", "0.5", "0.25"], tickdists=[]).partfunctions(0, 1, 1, 1)[0](), [tick((0, 1), None, 0), tick((1, 4), None, 2), tick((1, 2), None, 1), tick((3, 4), None, 2), tick((1, 1), None, 0)]) self.PartEqual(lin(labeldists=["1", "0.5"], tickdists=[], extendlabel=None).partfunctions(0, 1.5, 1, 1)[0](), [tick((0, 1), None, 0), tick((1, 2), None, 1), tick((1, 1), None, 0), tick((3, 2), None, 1)]) self.PartEqual(lin(labeldists=["1", "0.5"], tickdists=[], extendlabel=1).partfunctions(0, 1.2, 1, 1)[0](), [tick((0, 1), None, 0), tick((1, 2), None, 1), tick((1, 1), None, 0), tick((3, 2), None, 1)]) self.PartEqual(lin(labeldists=["1", "0.5"], tickdists=[], extendlabel=0).partfunctions(0, 1.2, 1, 1)[0](), [tick((0, 1), None, 0), tick((1, 2), None, 1), tick((1, 1), None, 0), tick((3, 2), None, 1), tick((2, 1), None, 0)]) self.PartEqual(lin(tickdists=["1"]).partfunctions(0, 1, 1, 1)[0](), [tick((0, 1), 0, 0), tick((1, 1), 0, 0)]) self.PartEqual(lin(tickdists=["1", "0.5"]).partfunctions(0, 1, 1, 1)[0](), [tick((0, 1), 0, 0), tick((1, 2), 1, None), tick((1, 1), 0, 0)]) self.PartEqual(lin(tickdists=["1", "0.5", "0.25"]).partfunctions(0, 1, 1, 1)[0](), [tick((0, 1), 0, 0), tick((1, 4), 2, None), tick((1, 2), 1, None), tick((3, 4), 2, None), tick((1, 1), 0, 0)]) self.PartEqual(lin(tickdists=["1", "0.5"], extendtick=None).partfunctions(0, 1.5, 1, 1)[0](), [tick((0, 1), 0, 0), tick((1, 2), 1, None), tick((1, 1), 0, 0), tick((3, 2), 1, None)]) self.PartEqual(lin(tickdists=["1", "0.5"], extendtick=1).partfunctions(0, 1.2, 1, 1)[0](), [tick((0, 1), 0, 0), tick((1, 2), 1, None), tick((1, 1), 0, 0), tick((3, 2), 1, None)]) self.PartEqual(lin(tickdists=["1", "0.5"], extendtick=0).partfunctions(0, 1.2, 1, 1)[0](), [tick((0, 1), 0, 0), tick((1, 2), 1, None), tick((1, 1), 0, 0), tick((3, 2), 1, None), tick((2, 1), 0, 0)]) self.PartEqual(lin(labeldists=["1"]).partfunctions(0, 1, 1, 1)[0](), [tick((0, 1), 0, 0), tick((1, 1), 0, 0)]) self.PartEqual(lin(labeldists=["1", "0.5"]).partfunctions(0, 1, 1, 1)[0](), [tick((0, 1), 0, 0), tick((1, 2), None, 1), tick((1, 1), 0, 0)]) self.PartEqual(lin(labeldists=["1", "0.5", "0.25"]).partfunctions(0, 1, 1, 1)[0](), [tick((0, 1), 0, 0), tick((1, 4), None, 2), tick((1, 2), None, 1), tick((3, 4), None, 2), tick((1, 1), 0, 0)]) self.PartEqual(lin(labeldists=["1", "0.5"], extendtick=None).partfunctions(0, 1.5, 1, 1)[0](), [tick((0, 1), 0, 0), tick((1, 2), None, 1), tick((1, 1), 0, 0), tick((3, 2), None, 1)]) self.PartEqual(lin(labeldists=["1", "0.5"], extendtick=None, extendlabel=1).partfunctions(0, 1.2, 1, 1)[0](), [tick((0, 1), 0, 0), tick((1, 2), None, 1), tick((1, 1), 0, 0), tick((3, 2), None, 1)]) self.PartEqual(lin(labeldists=["1", "0.5"], extendtick=None, extendlabel=0).partfunctions(0, 1.2, 1, 1)[0](), [tick((0, 1), 0, 0), tick((1, 2), None, 1), tick((1, 1), 0, 0), tick((3, 2), None, 1), tick((2, 1), 0, 0)])
def testDefault(self): ticks = [tick((0, 10), labellevel=0), tick((1, 10), labellevel=0), tick((1, 1), labellevel=0), tick((10, 1), labellevel=0)] default().labels(ticks) self.assertEqual([tex_expr(t.label) for t in ticks], ["0", "0.1", "1", "10"]) ticks = [tick((0, 10), labellevel=0), tick((1, 10), labellevel=0), tick((1, 1), labellevel=0), tick((10000, 1), labellevel=0)] default(minexp=1, skipmantissaunity=skipmantissaunity.never, uniformexp=False).labels(ticks) self.assertEqual([tex_expr(t.label) for t in ticks], [r"0", r"1\cdot{}10^{-1}", r"1", r"1\cdot{}10^{4}"]) ticks = [tick((0, 10), labellevel=0), tick((1, 10), labellevel=0), tick((1, 1), labellevel=0), tick((10000, 1), labellevel=0)] default(minexp=2, uniformexp=False).labels(ticks) self.assertEqual([tex_expr(t.label) for t in ticks], ["0", "0.1", "1", r"10^{4}"]) ticks = [tick((-1, 10), labellevel=0), tick((1, 1), labellevel=0), tick((10, 1), labellevel=0)] default(minexp=0).labels(ticks) self.assertEqual([tex_expr(t.label) for t in ticks], [r"-10^{-1}", r"10^{0}", r"10^{1}"]) ticks = [tick((0, 1), labellevel=0), tick((1, -10), labellevel=0), tick((15, 100), labellevel=0)] default(minnegexp=0, mantissatexter=decimal(equalprecision=True)).labels(ticks) self.assertEqual([tex_expr(t.label) for t in ticks], [r"0.0\cdot{}10^{0}", r"-1.0\cdot{}10^{-1}", r"1.5\cdot{}10^{-1}"]) ticks = [tick((0, 1), labellevel=0), tick((1, -10), labellevel=0), tick((15, 100), labellevel=0)] default(minnegexp=1, mantissatexter=decimal(equalprecision=True)).labels(ticks) self.assertEqual([tex_expr(t.label) for t in ticks], [r"0.0", r"-1.0\cdot{}10^{-1}", r"1.5\cdot{}10^{-1}"])
from pyx.graph.axis import painter, tick text.set(mode="latex") p = painter.regular(basepathattrs=[deco.earrow.normal], titlepos=0.95, titledist=-0.3, titledirection=None, outerticklength=graph.axis.painter.ticklength.normal, ) g = graph.graphxy(width=8, xaxisat=0, yaxisat=0, x=graph.axis.linear(title="$t$", min=-2.9, max=2.9, painter=p), y=graph.axis.linear(min=-0.05, max=1.9, manualticks=[tick.tick(0, None, None), tick.tick(0.5, label=r"$\frac{1}{2}$", ticklevel=0), tick.tick(1.5, label=r"$\frac{3}{2}$", ticklevel=0), ], painter=p)) def f(t,x): return t, sum([ x[i]*(t**i) for i in range(len(x)) ]) g.plot(graph.data.paramfunction("t", -3, 3, "x, y = f(t,x)", points=500, context={"f": f, "x":x2}), [graph.style.line([style.linewidth.Thin, style.linestyle.solid])]) g.plot(graph.data.paramfunction("t", -3, 3, "x, y = f(t,x)", points=500, context={"f": f, "x":x4}), [graph.style.line([style.linewidth.Thin, style.linestyle.solid])]) g.plot(graph.data.paramfunction("t", -3, 3, "x, y = f(t,x)", points=500, context={"f": f, "x":x8}), [graph.style.line([style.linewidth.Thin, style.linestyle.solid])]) px, py = g.pos(1.3, f(1.3, x2)[1])
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()