Hi,

On 26.09.07, Axel Freyn wrote:
> I would like to have something like a "mintickdists", to guarantee that e.g. 
> only Integers are used by the parter.

Yes, that's what I would do too. You could also try to fiddle with the
rating, but this could easily lead to cases, where no valid partitions
are found anymore. Better change the parter. Here we go:


    #!/usr/bin/env python

    from pyx import *

    d = [[0, 1], [3, 4], [2, 6], [5, 2], [6, 3]]


    class intparter(graph.axis.parter.autolin):

        def partfunction(self, data, testint=1):
            if data.sign == 1:
                if data.tickindex < len(self.variants) - 1:
                    data.tickindex += 1
                else:
                    data.tickindex = 0
                    data.base.num *= 10
            else:
                if data.tickindex:
                    data.tickindex -= 1
                else:
                    data.tickindex = len(self.variants) - 1
                    data.base.denom *= 10
            tickdists = [graph.axis.tick.rational(t) * data.base for t in 
self.variants[data.tickindex]]
            linearparter = graph.axis.parter.linear(tickdists=tickdists, 
extendtick=self.extendtick, epsilon=self.epsilon)
            if testint:
                tests = 0
                while tests < len(self.variants) or data.sign == 1:
                    if not tests:
                        ticks = linearparter.partfunctions(min=data.min, 
max=data.max, extendmin=data.extendmin, extendmax=data.extendmax)[0]()
                    else:
                        ticks = self.partfunction(data, testint=0)
                    for tick in ticks:
                        # if tick.labellevel is not None and tick.num % 
tick.denom: # labeled ticks are integer
                        if tick.num % tick.denom: # all ticks are integer
                            break
                    else:
                        return ticks
                    tests += 1
                return None
            else:
                return linearparter.partfunctions(min=data.min, max=data.max, 
extendmin=data.extendmin, extendmax=data.extendmax)[0]()


    intaxis = graph.axis.linear(parter=intparter())
    g = graph.graphxy(width=4.5, x=intaxis)
    g.plot(graph.data.list(d, x=1, y=2))
    g.writeEPSfile("test")


Some random notes:
- You can decide whether you want to allow (sub-)ticks at non-integer
  values or whether all ticks should be integers (see the comment in
  the code).
- The parter does not just stop for non-integer ticks, since it could
  be, that you have a partition with at tick at 2.5, but there are
  other integer partitions available for smaller ticks.
- We could force integer bases by adjusting the partfunctions method
  as well. Could gain speed in some cases, but would not lead to any
  different result.
- There was a bug introduced in changeset 2592, where I accidentally
  removed the range rating. Fixed in changeset 2882. Unfortunately I
  released this buggy code in 0.9, but we'll have a 0.10 soon anyway.
  Sorry for breaking the rating another time, back to as it was
  intended and worked in 0.8 and earlier. (I do have the intension,
  that the automatic partitioning should not change from version to
  version, but as you see, I'm missing that goal from time to time.)


http://pyx.svn.sourceforge.net/viewvc/pyx/trunk/pyx/pyx/graph/axis/axis.py?r1=2542&r2=2592
http://pyx.svn.sourceforge.net/viewvc/pyx/trunk/pyx/pyx/graph/axis/axis.py?r1=2808&r2=2884



André

-- 
by  _ _      _    Dr. André Wobst
   / \ \    / )   [EMAIL PROTECTED], http://www.wobsta.de/
  / _ \ \/\/ /    PyX - High quality PostScript and PDF figures
 (_/ \_)_/\_/     with Python & TeX: visit http://pyx.sourceforge.net/

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
PyX-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyx-user

Reply via email to