Hi Michael,

first of all, thanks a lot for providing a simple example. Without it I 
probably wouldn't have started to take a look into that right now.

Now, lets see: skip1=True does not work here, as there is an denomsuffix, so it 
would be wrong to remove the fraction. skip1 is about removing the fraction.

For skipdenom1 there is some documentation in the code:

        - skipdenom1 (boolean) just prints the numerator instead of
          the hole fraction, when the denominator is one and none of the 
parameters
          denomprefix, denominfix and denomsuffix are set and minuspos is not 
-1 or the
          fraction is positive

To my understanding (well, I've written the code, but this is many, many years 
ago) the code does that. We have a denomsuffix, hence skipdenom1 does not work 
to remove the 1. And it is good that the condition is done that way. skipdenom1 
is about skipping the denominator completely, which would also remove the 
1/\pi, and this surely would be bad!

What you want is something like skip1 just on the denominator, but without 
removing the fraction. (skipdenom1 is about removing the fraction.) Note that 
this is different from skipnum1, which only controls the numerator, and will 
not remove the fraction by its own. This means, that with the flags available 
in the rational texter the output you want just cannot be expressed. I don't 
see an easy solution to fix it within the texter without adding another flag 
for this case. But I think it would be more harm than good, as it is already 
rather complicated, and the problem you're facing is very specific (and 
uncommon).

Still, I can easily think of (at least) two solutions to work around it. The 
first solution is simpler, but has the problem, that it can only be used, when 
you know that there will be a tick at 1/\pi. The other is to do it in TeX ... 
yes, you heard right, you'll see in a moment. It's quite simple in the end of 
the day.

First solution:

from pyx import *

texter = graph.axis.texter.rational(denomsuffix=r"\pi", skip1=True,
skipdenom1=True)
g = graph.graphxy(
   width = 8,
   x = graph.axis.lin(min=0, max=1),
   y = graph.axis.lin(texter=texter, min=0, max=1,
                      manualticks=[graph.axis.tick.tick(1, label="1\over\pi", 
labelattrs=[text.mathmode])]),

)
g.writePDFfile()

Second solution:

from pyx import *

text.preamble(r"\def\myover#1{\over{\def\onepi{1\pi}\def\value{#1}\ifx\value\onepi\pi\else#1\fi}}")

texter = graph.axis.texter.rational(denomsuffix=r"\pi", skip1=True,
skipdenom1=True, over=r"{{%s}\myover{%s}}")
g = graph.graphxy(
   width = 8,
   x = graph.axis.lin(min=0, max=1),
   y = graph.axis.lin(texter=texter, min=0, max=1),
)
g.writePDFfile()

Best,


André

PS: Note that you should have a divisor on the axis to match the values to the 
labels. I guess you just omitted it in this minimized example. You will need to 
change the value of the manual tick position to 1/pi in the first solution.

PPS: I kept skip1 and skipdenom1 in the code, just as you posted it, to keep 
the changes minimal, but both flags have no effect anyway.

Am 15.10.2015 um 22:19 schrieb Michael Hartmann <[email protected]>:

> Hello,
> 
> I think I found a bug in the texter subsystem. The rational class doesn't
> handle skipdenom=True correctly when denomsuffix is set.
> 
> I have a small example:
> 
> 
> from pyx import *
> 
> texter = graph.axis.texter.rational(denomsuffix=r"\pi", skip1=True, 
> skipdenom1=True)
> g = graph.graphxy(
>    width = 8,
>    x = graph.axis.lin(min=0, max=1),
>    y = graph.axis.lin(texter=texter, min=0, max=1)
> )
> g.writePDFfile()
> 
> 
> The label of the upmost tick is "1/1pi" instead of "1/pi". According to the
> documentation the "1" in the denominator should be omitted.
> 
> The bug is in the file pyx/graph/axis/texter.py, method labels, starting at
> line 389. Unfortuntely, I didn't fully understand the logic of the code, so I
> cannot send you a patch. I've used the latest PyX release 0.14 and Python
> 3.4.2.
> 
> Thank you very much for your help! 
> 
> Kind regards,
> 
> --Michael
> 
> 
> 
> ------------------------------------------------------------------------------
> _______________________________________________
> PyX-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/pyx-user

-- 
by  _ _      _    Dr. André Wobst, Amselweg 22, 85716 Unterschleißheim
   / \ \    / )   [email protected], http://www.wobsta.de/
  / _ \ \/\/ /    PyX - High quality PostScript and PDF figures
 (_/ \_)_/\_/     with Python & TeX: visit http://pyx.sourceforge.net/

Attachment: smime.p7s
Description: S/MIME cryptographic signature

------------------------------------------------------------------------------
_______________________________________________
PyX-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyx-user

Reply via email to