## Trouble aligning scales

Forum for PyNomo discussion.
jasonwalker
Posts: 27
Joined: Sun Sep 11, 2011 3:54 pm

### Trouble aligning scales

Hi all,

I'm working on a compound nomogram, the first scale of which has different values for girls and boys. (It has to do with median weights for a particular age). f(x) in each case is a logistic eqn: for boys it's 24-(8.75/(1+((age/14.7)^5))), for girls it's 22-(6.75/(1+((age/12.7)^6)))

I've drawn this out by hand previously, so I know what it's supposed to look like. However, the scales don't align, however I try - indeed the align command doesn't seem to make a difference no matter what I put in there. (I initially thought I was being very clever by using wolfram alpha to generate a conversion function, but even if I use a simple arbitrary scalar, I still get the same result.) Here's the code for the first scale, as two simple type eight blocks. No align function, as it doesn't seem to make a difference.

Code: Select all

`"""    agescale.py         Copyright (C) 2011 Jason Walker     """from pynomo.nomographer import * Boys_para={        'tag':'Age',        'u_min':5,        'u_max':19,        'function':lambda u:(24-(8.75/(1+((u/14.7)**5)))),        'title':r'Boys',        'tick_levels':2,        'tick_text_levels':1,        'tick_side':'left',        'title_x_shift':-0.5        } Girls_para={        'tag':'Age',        'u_min':5,        'u_max':19,        'function':lambda u:(22-(6.75/(1+((u/12.7)**6)))),        'align':lambda u:u,        'title':r'Girls',        'tick_levels':2,        'tick_text_levels':1,        'tick_side':'right',        'title_x_shift':0.5} Boys_block={         'block_type':'type_8',            'f_params':Boys_para         }Girls_block={         'block_type':'type_8',            'f_params':Girls_para            } main_params={              'filename':'agescale.pdf',              'paper_height':20.0,              'paper_width':2.0,              'block_params':[Boys_block,Girls_block],              'transformations':[('scale paper',)]              }Nomographer(main_params)`

When I run this, the 19 mark on the girls scale is about 16.7 on the boys - which is incorrect.
Now here's the funny thing: If I don't tag them, they line up perfectly. Delete the tag commands, and it produces a double scale where 19 on the girls is ~ 17.6 on the boys, which is bang on perfect.

I'd leave it at that, but obviously when you move on to a more complicated nomogram you get your girl scale hanging around looking lost above the nomogram.

All advice gratefully accepted.

Jason
Leif
Posts: 55
Joined: Mon Dec 31, 2007 3:03 pm
Location: Finland
Contact:

### Re: Trouble aligning scales

Please find attached code that works. Note the line:

Code: Select all

` 'align_func':lambda age:inv_boys(girls(age)),`

You need the inv_boys() function because the scaling are not linear.

Code: Select all

`"""    agescale.py    Copyright (C) 2011 Jason Walker"""from pynomo.nomographer import *def boys(age):    return (24-(8.75/(1+((age/14.7)**5.0))))def girls(age):    return (22-(6.75/(1+((age/12.7)**6.0))))def inv_girls(value):    return 12.7*(6.75/(22.0-value)-1.0)**(1.0/6.0)def inv_boys(value):    return 14.7*(8.75/(24.0-value)-1.0)**(1.0/5.0)print "testing"print "B(19) = %g"%boys(19.0)print "G(19) = %g"%girls(19.0)print "inv_B(%g) = %g"%(boys(19.0),inv_boys(boys(19.0)))print "inv_G(%g) = %g"%(girls(19.0),inv_girls(girls(19.0)))Boys_para={        'tag':'Age',        'u_min':5,        'u_max':19,        'function':lambda age:boys(age),        'title':r'Boys',        'tick_levels':2,        'tick_text_levels':1,        'tick_side':'left',        'title_x_shift':-0.5        }Girls_para={        'tag':'Age',        'u_min':5,        'u_max':19,        'function':lambda age:girls(age),        'align_func':lambda age:inv_boys(girls(age)),        'title':r'Girls',        'tick_levels':2,        'tick_text_levels':1,        'tick_side':'right',        'title_x_shift':0.5}Boys_block={         'block_type':'type_8',            'f_params':Boys_para         }Girls_block={         'block_type':'type_8',            'f_params':Girls_para            }main_params={              'filename':'agescale_align.pdf',              'paper_height':20.0,              'paper_width':2.0,              'block_params':[Boys_block,Girls_block],              'transformations':[('scale paper',)]              }Nomographer(main_params)`

br,

\leif
jasonwalker
Posts: 27
Joined: Sun Sep 11, 2011 3:54 pm

### Re: Trouble aligning scales

Aha!

Perfect. Thank you very much indeed!

Jason
jasonwalker
Posts: 27
Joined: Sun Sep 11, 2011 3:54 pm

### Re: Trouble aligning scales

It's been a long time coming, but the full nomogram I was working on here has finally made it into print. http://onlinelibrary.wiley.com/doi/10.1111/anae.12860/full Leif, you'll be glad to hear that you're mentioned in the acknowledgements.

Jason
Leif
Posts: 55
Joined: Mon Dec 31, 2007 3:03 pm
Location: Finland
Contact:

Thanks!

br,

\leif