Difference between revisions of "Example:compound nomograph 1"
(→Compound nomograph example 1) |
(→Source code of simple example of type 1) |
||
Line 25: | Line 25: | ||
| file = [http://nomography.org/wiki/images/a/ac/Ex_type1_nomo_1.pdf Ex_type1_nomo_1.pdf] | | file = [http://nomography.org/wiki/images/a/ac/Ex_type1_nomo_1.pdf Ex_type1_nomo_1.pdf] | ||
}} | }} | ||
− | ==== Source code of simple example | + | ==== Source code of simple compound nomograph example ==== |
<source lang=python> | <source lang=python> | ||
""" | """ | ||
− | + | ex_compound_nomo_1.py | |
− | + | Compound nomograph: (A+B)/E=F/(CD) | |
Copyright (C) 2007-2008 Leif Roschier | Copyright (C) 2007-2008 Leif Roschier | ||
Line 49: | Line 49: | ||
from nomographer import * | from nomographer import * | ||
− | + | # type 1 | |
+ | A_params={ | ||
'u_min':0.0, | 'u_min':0.0, | ||
'u_max':10.0, | 'u_max':10.0, | ||
'function':lambda u:u, | 'function':lambda u:u, | ||
− | 'title':r'$ | + | 'title':r'$A$', |
'tick_levels':2, | 'tick_levels':2, | ||
'tick_text_levels':1, | 'tick_text_levels':1, | ||
} | } | ||
− | + | B_params={ | |
'u_min':0.0, | 'u_min':0.0, | ||
'u_max':10.0, | 'u_max':10.0, | ||
'function':lambda u:u, | 'function':lambda u:u, | ||
− | 'title':r'$ | + | 'title':r'$B$', |
'tick_levels':2, | 'tick_levels':2, | ||
'tick_text_levels':1, | 'tick_text_levels':1, | ||
} | } | ||
− | + | R1a_params={ | |
'u_min':0.0, | 'u_min':0.0, | ||
− | 'u_max':-10.0, | + | 'u_max':10.0, |
+ | 'function':lambda u:-u, | ||
+ | 'title':'', | ||
+ | 'tick_levels':0, | ||
+ | 'tick_text_levels':0, | ||
+ | 'tag':'r1' | ||
+ | } | ||
+ | block_1_params={ | ||
+ | 'block_type':'type_1', | ||
+ | 'width':10.0, | ||
+ | 'height':10.0, | ||
+ | 'f1_params':A_params, | ||
+ | 'f2_params':B_params, | ||
+ | 'f3_params':R1a_params, | ||
+ | } | ||
+ | # type 4 | ||
+ | R1b_params={ | ||
+ | 'u_min':1.0, | ||
+ | 'u_max':10.0, | ||
'function':lambda u:u, | 'function':lambda u:u, | ||
− | 'title':r'$ | + | 'title':r'$R_1$', |
− | 'tick_levels': | + | 'tick_levels':0, |
+ | 'tick_text_levels':0, | ||
+ | 'tick_side':'right', | ||
+ | 'title_draw_center':True, | ||
+ | 'title_opposite_tick':False, | ||
+ | 'tag':'r1' | ||
+ | } | ||
+ | E_params={ | ||
+ | 'u_min':1.0, | ||
+ | 'u_max':10.0, | ||
+ | 'function':lambda u:u, | ||
+ | 'title':r'$E$', | ||
+ | 'tick_levels':3, | ||
'tick_text_levels':1, | 'tick_text_levels':1, | ||
+ | 'tick_side':'right', | ||
+ | 'title_draw_center':True, | ||
+ | 'title_opposite_tick':False, | ||
+ | } | ||
+ | F_params={ | ||
+ | 'u_min':1.0, | ||
+ | 'u_max':10.0, | ||
+ | 'function':lambda u:u, | ||
+ | 'title':r'$F$', | ||
+ | 'tick_levels':3, | ||
+ | 'tick_text_levels':1, | ||
+ | 'tick_side':'left', | ||
+ | 'title_draw_center':True, | ||
+ | 'title_opposite_tick':True, | ||
+ | } | ||
+ | R2a_params={ | ||
+ | 'u_min':1.0, | ||
+ | 'u_max':10.0, | ||
+ | 'function':lambda u:u, | ||
+ | 'title':r'$R_2$', | ||
+ | 'tick_levels':0, | ||
+ | 'tick_text_levels':0, | ||
+ | 'tick_side':'left', | ||
+ | 'title_draw_center':True, | ||
+ | 'title_opposite_tick':False, | ||
+ | 'tag':'r2' | ||
} | } | ||
+ | block_2_params={ | ||
+ | 'block_type':'type_4', | ||
+ | 'f1_params':R1b_params, | ||
+ | 'f2_params':E_params, | ||
+ | 'f3_params':F_params, | ||
+ | 'f4_params':R2a_params, | ||
+ | 'mirror_x':True | ||
+ | } | ||
+ | # type 2 N | ||
+ | R2b_params={ | ||
+ | 'u_min':0.0, | ||
+ | 'u_max':10.0, | ||
+ | 'function':lambda u:u, | ||
+ | 'title':r'$$', | ||
+ | 'tick_levels':0, | ||
+ | 'tick_text_levels':0, | ||
+ | 'tag':'r2' | ||
+ | } | ||
− | + | C_params={ | |
− | 'block_type':' | + | 'u_min':0.5, |
+ | 'u_max':5.0, | ||
+ | 'function':lambda u:u, | ||
+ | 'title':r'$C$', | ||
+ | 'tick_levels':3, | ||
+ | 'tick_text_levels':1, | ||
+ | 'tick_side':'left', | ||
+ | } | ||
+ | |||
+ | D_params={ | ||
+ | 'u_min':1.0, | ||
+ | 'u_max':10.0, | ||
+ | 'function':lambda u:u, | ||
+ | 'title':r'$D$', | ||
+ | 'tick_levels':3, | ||
+ | 'tick_text_levels':1, | ||
+ | } | ||
+ | |||
+ | block_3_params={ | ||
+ | 'block_type':'type_2', | ||
'width':10.0, | 'width':10.0, | ||
'height':10.0, | 'height':10.0, | ||
− | 'f1_params': | + | 'f1_params':R2b_params, |
− | 'f2_params': | + | 'f2_params':C_params, |
− | 'f3_params': | + | 'f3_params':D_params, |
+ | 'mirror_y':True | ||
} | } | ||
main_params={ | main_params={ | ||
− | 'filename':' | + | 'filename':'ex_compound_nomo_1.pdf', |
'paper_height':10.0, | 'paper_height':10.0, | ||
'paper_width':10.0, | 'paper_width':10.0, | ||
− | 'block_params':[block_1_params], | + | 'block_params':[block_1_params,block_2_params,block_3_params], |
'transformations':[('rotate',0.01),('scale paper',)], | 'transformations':[('rotate',0.01),('scale paper',)], | ||
− | |||
} | } | ||
Nomographer(main_params) | Nomographer(main_params) | ||
+ | |||
</source> | </source> | ||
Revision as of 19:49, 28 August 2008
Contents
Compound nomograph example 1
In this example we construct compound nomograph of equation
[math]\frac{A+B}{E}=\frac{F}{CD} \,[/math]
just as an example. The equation is split into three equations that each are blocks:
[math]A+B=R_1 \,\,\,\,\,\,\,[/math] (type 1)
[math]CD=R_2 \,\,\,\,\,\,\,[/math] (type 2)
[math]\frac{R_1}{E}= \frac{F}{R_2} \,\,\,\,\,\,\,[/math] (type 4)
It is iterative process in practice with PyNomo to construct compound nomograps. One should generate nomographs and correct for example block mirroring and axis tick sides, levels and title positions. The following is an example of result after some ten iterations. Note the 'tag' key that defines how blocks aling with respect to each other. User has to take care that aligned scalings are really equal between blocks. Best practice may be to print in early iterations the scalings and check they are equal.
Simple example
Simple example: Type 1 | |
---|---|
![]() |
|
Generated portable document file (pdf): | Ex_type1_nomo_1.pdf |
Source code of simple compound nomograph example
""" ex_compound_nomo_1.py Compound nomograph: (A+B)/E=F/(CD) Copyright (C) 2007-2008 Leif Roschier This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ from nomographer import * # type 1 A_params={ 'u_min':0.0, 'u_max':10.0, 'function':lambda u:u, 'title':r'$A$', 'tick_levels':2, 'tick_text_levels':1, } B_params={ 'u_min':0.0, 'u_max':10.0, 'function':lambda u:u, 'title':r'$B$', 'tick_levels':2, 'tick_text_levels':1, } R1a_params={ 'u_min':0.0, 'u_max':10.0, 'function':lambda u:-u, 'title':'', 'tick_levels':0, 'tick_text_levels':0, 'tag':'r1' } block_1_params={ 'block_type':'type_1', 'width':10.0, 'height':10.0, 'f1_params':A_params, 'f2_params':B_params, 'f3_params':R1a_params, } # type 4 R1b_params={ 'u_min':1.0, 'u_max':10.0, 'function':lambda u:u, 'title':r'$R_1$', 'tick_levels':0, 'tick_text_levels':0, 'tick_side':'right', 'title_draw_center':True, 'title_opposite_tick':False, 'tag':'r1' } E_params={ 'u_min':1.0, 'u_max':10.0, 'function':lambda u:u, 'title':r'$E$', 'tick_levels':3, 'tick_text_levels':1, 'tick_side':'right', 'title_draw_center':True, 'title_opposite_tick':False, } F_params={ 'u_min':1.0, 'u_max':10.0, 'function':lambda u:u, 'title':r'$F$', 'tick_levels':3, 'tick_text_levels':1, 'tick_side':'left', 'title_draw_center':True, 'title_opposite_tick':True, } R2a_params={ 'u_min':1.0, 'u_max':10.0, 'function':lambda u:u, 'title':r'$R_2$', 'tick_levels':0, 'tick_text_levels':0, 'tick_side':'left', 'title_draw_center':True, 'title_opposite_tick':False, 'tag':'r2' } block_2_params={ 'block_type':'type_4', 'f1_params':R1b_params, 'f2_params':E_params, 'f3_params':F_params, 'f4_params':R2a_params, 'mirror_x':True } # type 2 N R2b_params={ 'u_min':0.0, 'u_max':10.0, 'function':lambda u:u, 'title':r'$$', 'tick_levels':0, 'tick_text_levels':0, 'tag':'r2' } C_params={ 'u_min':0.5, 'u_max':5.0, 'function':lambda u:u, 'title':r'$C$', 'tick_levels':3, 'tick_text_levels':1, 'tick_side':'left', } D_params={ 'u_min':1.0, 'u_max':10.0, 'function':lambda u:u, 'title':r'$D$', 'tick_levels':3, 'tick_text_levels':1, } block_3_params={ 'block_type':'type_2', 'width':10.0, 'height':10.0, 'f1_params':R2b_params, 'f2_params':C_params, 'f3_params':D_params, 'mirror_y':True } main_params={ 'filename':'ex_compound_nomo_1.pdf', 'paper_height':10.0, 'paper_width':10.0, 'block_params':[block_1_params,block_2_params,block_3_params], 'transformations':[('rotate',0.01),('scale paper',)], } Nomographer(main_params)
Parameters for type 1
Axis parameters
Specific axis parameters for type 1 | ||
---|---|---|
Parameter | Default value | Explanation |
'function' | - |
Function in the equation |
'u_min' | - |
Minimum value of function variable |
'u_max' | - |
Maximum value of function variable |
Common axis parameters | ||
---|---|---|
Parameter | Default value | Explanation |
'ID' | 'none' |
To identify the axis |
'tag' | 'none' |
To align blocks w.r.t each other along axes with same tag |
'title' | '' |
Axis title |
'title_x_shift' | 0.0 |
Title shift in x-direction |
'title_y_shift' | 0.25 |
Title shift in y-direction |
'scale_type' | 'linear' |
Scale type. can be
|
'tick_levels' | 4 |
How many levels (minor, minor-minor, etc.) of ticks are drawn. Largest effect to 'linear' scale. |
'tick_text_levels' | 3 |
How many levels (minor, minor-minor, etc.) of texts are drawn. Largest effect to 'linear' scale. |
'tick_side' | 'right' |
Tick and text side in final paper. Can be:
|
'reference' | False |
If axis is treated as reference line that is a turning point. |
'reference_padding' | 0.2 |
Fraction of reference line over other lines |
'manual_axis_data' | {} |
Manually set tick/point positions and text positions. Could be for example: {1:'1',3.14:r'$\pi$',5:'5',7:'seven',10:'10'} |
'title_draw_center' | False |
Title is drawn to center of line |
'title_distance_center' | 0.5 |
Distance of centered title from line if centered title |
'title_opposite_tick' | True |
Title in opposite direction w.r.t ticks |
'align_func' | lambda u:u |
function to align different scalings |
'align_x_offset' | 0.0 |
If axis is aligned with other axis, this value x offsets final scale |
'align_y_offset' | 0.0 |
If axis is aligned with other axis, this value y offsets final scale |
'text_format' | r"$%4.4g$ " |
Format for numbers in scale. |
'extra_params' | -- |
List of dictionary of params to be drawn additionally. |
'text_distance_#' | -- |
where #=0,1,2,3 or 4. Distance of text from scale line. Number corresponds to the level, where 0 is the major tick and 4 is the most minor ticks. |
'grid_length_#' | -- |
where #=0,1,2,3 or 4. Length of the tick. Number corresponds to the level, where 0 is the major tick and 4 is the most minor ticks. |
'text_size_#' | -- |
where #=0,1,2,3 or 4. Text size. For example: text.size.small, text.size.scriptsize or text.size.tiny . Number corresponds to the level, where 0 is the major tick and 4 is the most minor ticks. |
'text_size_log_#' | -- |
where #=0,1 or 2. Text size. For example: text.size.small, text.size.scriptsize or text.size.tiny . Number corresponds to the level, where 0 is the major tick and 2 is the most minor ticks. |
'full_angle' | False |
If true, text can be upside down, otherwise +- 90 degrees from horizontal. Good foor example for full circle scales. |
'extra_angle' | 0.0 |
Angle to rotate tick text from horizontal along tick. |
'text_horizontal_align_center' | False |
Aligns tick text horizontally to center. Good when text rotated 90 degrees. |
'turn_relative' | False |
Side left or right is relative according to traveling of scale from min to max. |
'arrow_size' | 0.2 |
Used with arrow scale. |
'arrow_length' | 1.0 |
Used with arrow scale. |
'arrow_color' | color.rgb.black |
Used with arrow scale. |
'axis_color' | color.rgb.black |
Color of axis. |
'text_color' | color.rgb.black |
Color of tick texts. |
'extra_titles' | [] |
List of extra title dicts for scale. Could be i.e. [{'dx':1.0, 'dy':1.0, 'text':'extra title 1', 'width':5, 'pyx_extra_defs':[color.rgb.red,text.size.Huge] }, {'text':'extra title 2'} ] |
'base_start' | None |
Defines number with 'base_stop' (instead of u_min or u_max) to find major tick decades. |
'base_stop' | None |
Defines number with 'base_start' (instead of u_min or u_max) to find major tick decades. |
Block parameters
Specific block parameters for type 1 | ||
---|---|---|
Parameter | Default value | Explanation |
'block_type' | 'type_1' |
This is type 1 block |
'width' | 10.0 |
Block width (to be scaled) |
'height' | 10.0 |
Block height (to be scaled) |
'f1_params' | -- |
Axis params for function f1 |
'f2_params' | -- |
Axis params for function f2 |
'f3_params' | -- |
Axis params for function f3 |
'mirror_x' | False |
If x-axis is mirrored |
'mirror_y' | False |
If y-axis is mirrored |
General main parameters
General main parameters | ||
---|---|---|
Parameter | Default value | Explanation |
'filename' | -- |
filename of generated pdf |
'paper_height' | 10.0 |
Height of paper (roughly, ticks and texts extend this) |
'paper_width' | 10.0 |
Width of paper (roughly, ticks and texts extend this) |
'block_params' | -- |
List of blocks that make the nomograph |
'transformations' | -- |
List of transformations to transform nomograph |
'title_str' | -- |
Title string of nomograph |
'title_x' | -- |
Title x-position |
'title_y' | -- |
Title y-position |
'title_box_width' | -- |
Title box width |
'title_color' | color.rgb.black |
Title color |
'make_grid' | False |
If True, draws grid to help position texts, etc. |
'draw_lines' | False |
If True, draws (brute-force) lines according to 'line_params' |
'line_params' | [] |
OBSOLETE, USE ISOPLETHS. List of dics of (brute-force) lines. For example: [{'coords':[[0,0,1,1],[2,2,3,3]], 'line_style':[color.cmyk.Black, style.linewidth.thick, style.linestyle.dashed], 'circle_size':0.0005, 'circle_color':color.cmyk.Black, }] |
'pre_func' | None |
PyX function(canvas) to draw under nomograph. Function definitin could be: def post(c): c.stroke(path.line(2, 2, 15, 2) + path.line(15, 2, 10, 15) + path.line(15, 15, 2, 15) + path.line(2, 15, 2, 2)) |
'post_func' | None |
PyX function(canvas) to draw over nomograph. Definiton same as for 'pre_func'. |
'debug' | False |
If True, prints dicts of definions. Feature in PyNomo 0.2.1: not all default values are printed. |
'extra_texts' | [] |
List of dicts defining extra texts. Could be for example: [{'x':1.0, 'y':1.0, 'text':'testing', 'width':5, 'pyx_extra_defs':[color.rgb.red,text.size.Huge] }, {'x':1.0, 'y':2.0, 'text':'testing', 'width':5, 'pyx_extra_defs':[color.rgb.green] }, {'x':1.0, 'y':3.0, 'text':r"line \par break", 'width':5, 'pyx_extra_defs':[color.rgb.blue,text.size.tiny] }] |
'isopleth_params' | [{}] |
List of dicts defining isopleths. Could be for example: [{'color':'MidnightBlue', 'linewidth':'THICK', 'linestyle':'dashdotted', 'transparency':0.2}, {'color':'Orange', 'linewidth':'THIN', 'linestyle':'dashdotted', 'transparency':0.9}] |