1--[[ 2 Multi-lingual version of the first page of example 4. 3 4 Copyright (C) 2009 Werner Smekal 5 6 Thanks to the following for providing translated strings for this example: 7 Valery Pipin (Russian) 8 9 This file is part of PLplot. 10 11 PLplot is free software you can redistribute it and/or modify 12 it under the terms of the GNU Library General Public License as published 13 by the Free Software Foundation either version 2 of the License, or 14 (at your option) any later version. 15 16 PLplot is distributed in the hope that it will be useful, 17 but WITHOUT ANY WARRANTY without even the implied warranty of 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 GNU Library General Public License for more details. 20 21 You should have received a copy of the GNU Library General Public License 22 along with PLplot if not, write to the Free Software 23 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 24--]] 25 26 27--[[ 28 This example designed just for devices (e.g., psttfc and the 29 cairo-related devices) that use the pango and fontconfig libraries. The 30 best choice of glyph is selected by fontconfig and automatically rendered 31 by pango in way that is sensitive to complex text layout (CTL) language 32 issues for each unicode character in this example. Of course, you must 33 have the appropriate TrueType fonts installed to have access to all the 34 required glyphs. 35 36 Translation instructions: The strings to be translated are given by 37 x_label, y_label, alty_label, title_label, and line_label below. The 38 encoding used must be UTF-8. 39 40 The following strings to be translated involve some scientific/mathematical 41 jargon which is now discussed further to help translators. 42 43 (1) dB is a decibel unit, see http://en.wikipedia.org/wiki/Decibel . 44 (2) degrees is an angular measure, see 45 http://en.wikipedia.org/wiki/Degree_(angle) . 46 (3) low-pass filter is one that transmits (passes) low frequencies. 47 (4) pole is in the mathematical sense, see 48 http://en.wikipedia.org/wiki/Pole_(complex_analysis) . "Single Pole" 49 means a particular mathematical transformation of the filter function has 50 a single pole, see 51 http://ccrma.stanford.edu/~jos/filters/Pole_Zero_Analysis_I.html . 52 Furthermore, a single-pole filter must have an inverse square decline 53 (or -20 db/decade). Since the filter plotted here does have that 54 characteristic, it must by definition be a single-pole filter, see also 55 http://www-k.ext.ti.com/SRVS/Data/ti/KnowledgeBases/analog/document/faqs/1p.htm 56 (5) decade represents a factor of 10, see 57 http://en.wikipedia.org/wiki/Decade_(log_scale) . 58--]] 59 60-- initialise Lua bindings for PLplot examples. 61dofile("plplot_examples.lua") 62 63x_label = { "Frequency", "Частота" } 64y_label = { "Amplitude (dB)", "Амплитуда (dB)" } 65alty_label = { "Phase shift (degrees)", "Фазовый сдвиг (градусы)" } 66-- Short rearranged versions of y_label and alty_label. 67legend_text = { 68 {"Amplitude", "Phase shift"}, 69 {"Амплитуда", "Фазовый сдвиг"} 70 } 71title_label = { "Single Pole Low-Pass Filter", "Однополюсный Низко-Частотный Фильтр" } 72line_label = { "-20 dB/decade", "-20 dB/десяток" } 73 74-- return single bit (for OR) 75function bit(x,b) 76 return ((x % 2^b) - (x % 2^(b-1)) > 0) 77end 78 79-- logic OR for number values 80 81function lor(x,y) 82 result = 0 83 for p=1,8 do result = result + (((bit(x,p) or bit(y,p)) == true) and 2^(p-1) or 0) end 84 return result 85end 86 87---------------------------------------------------------------------------- 88-- plot1 89-- 90-- Log-linear plot. 91---------------------------------------------------------------------------- 92 93function plot1(type, x_label, y_label, alty_label, title_label, line_label, legend_text) 94 freql = {} 95 ampl = {} 96 phase = {} 97 98 pl.adv(0) 99 100 -- Set up data for log plot 101 102 f0 = 1 103 for i = 1, 101 do 104 freql[i] = -2 + (i-1)/20 105 freq = 10^freql[i] 106 ampl[i] = 20 * math.log(1/math.sqrt(1+(freq/f0)^2),10) 107 phase[i] = -180/math.pi*math.atan(freq/f0) 108 end 109 110 pl.vpor(0.15, 0.85, 0.1, 0.9) 111 pl.wind(-2, 3, -80, 0) 112 113 -- Try different axis and labelling styles. 114 pl.col0(1) 115 if type==0 then 116 pl.box("bclnst", 0, 0, "bnstv", 0, 0) 117 elseif type==1 then 118 pl.box("bcfghlnst", 0, 0, "bcghnstv", 0, 0) 119 else 120 pl.abort("type must be 0 or 1") 121 pl.plend() 122 os.exit() 123 end 124 125 -- Plot ampl vs freq 126 pl.col0(2) 127 pl.line(freql, ampl) 128 pl.col0(2) 129 pl.ptex(1.6, -30, 1, -20, 0.5, line_label) 130 131 -- Put labels on 132 pl.col0(1) 133 pl.mtex("b", 3.2, 0.5, 0.5, x_label) 134 pl.mtex("t", 2, 0.5, 0.5, title_label) 135 pl.col0(2) 136 pl.mtex("l", 5, 0.5, 0.5, y_label) 137 138 -- For the gridless case, put phase vs freq on same plot 139 if type==0 then 140 pl.col0(1) 141 pl.wind(-2, 3, -100, 0) 142 pl.box("", 0, 0, "cmstv", 30, 3) 143 pl.col0(3) 144 pl.line(freql, phase) 145 pl.string(freql, phase, "#(728)") 146 pl.col0(3) 147 pl.mtex("r", 5, 0.5, 0.5, alty_label) 148 nlegend = 2 149 else 150 nlegend = 1 151 end 152 153 -- Draw a legend. 154 opt_array = {} 155 text_colors = {} 156 text = {} 157 box_colors = {} 158 box_patterns = {} 159 box_scales = {} 160 box_line_widths = {} 161 line_colors = {} 162 line_styles = {} 163 line_widths = {} 164 symbol_colors = {} 165 symbol_scales = {} 166 symbol_numbers = {} 167 symbols = {} 168 169 -- Data for the first legend entry. 170 opt_array[1] = pl.PL_LEGEND_LINE 171 text_colors[1] = 2 172 text[1] = legend_text[1] 173 -- box data unused so initialize to arbitrary values. 174 box_colors[1] = 0 175 box_patterns[1] = 0 176 box_scales[1] = 0 177 box_line_widths[1] = 0. 178 line_colors[1] = 2 179 line_styles[1] = 1 180 line_widths[1] = 1. 181 -- unused arbitrary data 182 symbol_colors[1] = 0 183 symbol_scales[1] = 0 184 symbol_numbers[1] = 0 185 symbols[1] = "" 186 187 -- Data for the second legend entry. 188 if nlegend > 1 then 189 opt_array[2] = lor(pl.PL_LEGEND_LINE, pl.PL_LEGEND_SYMBOL) 190 text_colors[2] = 3 191 text[2] = legend_text[2] 192 -- box data unused so initialize to arbitrary values. 193 box_colors[2] = 0 194 box_patterns[2] = 0 195 box_scales[2] = 0 196 box_line_widths[2] = 0. 197 line_colors[2] = 3 198 line_styles[2] = 1 199 line_widths[2] = 1. 200 symbol_colors[2] = 3 201 symbol_scales[2] = 1. 202 symbol_numbers[2] = 4 203 symbols[2] = "#(728)" 204 end 205 206 pl.scol0a( 15, 32, 32, 32, 0.70 ) 207 208 legend_width, legend_height = pl.legend( 209 lor(pl.PL_LEGEND_BACKGROUND, pl.PL_LEGEND_BOUNDING_BOX), 0, 0.0, 0.0, 210 0.1, 15, 1, 1, 0, 0, opt_array, 1.0, 1.0, 2.0, 211 1., text_colors, text, 212 box_colors, box_patterns, box_scales, box_line_widths, 213 line_colors, line_styles, line_widths, 214 symbol_colors, symbol_scales, symbol_numbers, symbols ) 215 216end 217 218 219---------------------------------------------------------------------------- 220-- main 221-- 222-- Illustration of logarithmic axes, and redefinition of window. 223---------------------------------------------------------------------------- 224 225-- Parse and process command line arguments 226pl.parseopts(arg, pl.PL_PARSE_FULL) 227 228-- Initialize plplot 229pl.init() 230nlang = # x_label 231if nlang ~= (# y_label) or 232 nlang ~= (# alty_label) or 233 nlang ~= (# title_label) or 234 nlang ~= (# line_label) or 235 nlang ~= (# legend_text) then 236 pl.abort("All data must be expressed in the same number of languages") 237 pl.plend() 238 os.exit() 239end 240 241pl.font(2) 242-- Make log plots using two different styles. 243for i = 1, nlang do 244 plot1(0, x_label[i], y_label[i], alty_label[i], title_label[i], line_label[i], legend_text[i]) 245end 246 247pl.plend() 248