gnuplot: How to enable thousand separators (digit grouping)? - localization

I'm on German Windows 8.1 64Bit with gnuplot 4.6.5, using the svg terminal. If I plot datafiles that have big numbers, like "one million", gnuplot does not print a digit grouping sign.
For example, if my datafile has values in the order of one million, I want the numbers at the y-axis be displayed as 1.000.000 (with . being the group sign, not the decimal sign!), but gnuplot gives me just 1000000.
The option set decimalsign locale just changes the decimal sign (separator between whole number and fractional part, like 1+1/2 = 1,5 with , being the decimal sign). But neither setting decimalsign nor not calling this command at all shows digit grouping signs in the plot. I only get ugly 1000000 or 1500000 instead of 1.000.000 or 1.500.000.
I also tried
set decimal locale
set format y "%'f"
which just gives me at all tics the label "%'f", instead of the numbers! Each tic has just "%'f", again and again. It just prints the format string as is into the plot and no numbers at all. The console output is decimal_sign in locale is , which is correct for german locale, so gnuplot recognizes it correctly. In my control panel of Windows the thousand separator is set correctly to . and the decimal sign to , too.
Setting tic by tic by hand is no option. I.e. set ytics add ('1.000.000' 1e6) for dozenz of dozenz tics is no option for me.
How do I automatically get thousand separators in gnuplot?

That seems not to work on Windows. From the gnuplot documentation
Internationalization (locale settings): Gnuplot uses the C runtime library routine setlocale() to control locale-specific formatting of input and output number, times, and date strings. The locales available, and the level of support for locale features such as "thousands’ grouping separator", depend on the internationalization support provided by your individual machine.
And judging from questions like How can I add a thousands separator to a double in C on Windows? Printing integers with thousands separators in Windows using C it is not possible since the apostrophe in the format string is a Unix specialty and not a C standard.
I think there is no workaround to get this working on Windows with autoscaling.
For the records: The following script works fine on Linux:
set format "%'.0f"
set xrange [0:1e6]
plot x

Only ., , and are possible as separator (at least Linux). E.g. "french" gives a space:
set decimalsign locale "french" # thousand separator becomes ` `
set decimalsign "."
set format "%'.2f"; # `'` activates the thousand separator
pl [0:1e5] x

Not the most glamorous of solutions, especially if you've got a lot of tics but you could do something like
set ytics ("1.000.000" 1e6, "1.500.000" 1.5e6, etc.)
I'd be interested to hear of anything nicer!

Just for fun and feasibilty... If you absolutely need thousand separators, you can construct a workaround for Windows (with some complexity and limitations). Tested with gnuplot 5.2.6.
Basic recipe:
define a function which converts numbers into text with thousand separators.
set the tic labels yourself using text with thousand separators
place the tic labels by trying to "mimic" gnuplot's setting of tic labels. For this, use gnuplot's suggestions about the scaling by plotting to a dummy terminal first. For this, this post of #Christoph is very helpful.
Code:
### add thousand separators to tic labels for Windows
reset session
# settings for thousand separator
ts = "'" # thousand separator
ThousandSeparator(a,ts) = abs(a)>=1000 ? (TS_a=sprintf("%.0f",a), TS_b=strlen(TS_a), \
TS_c=strstrt(TS_a,'-')+1, TS_d=TS_c>1?'-':'', (sum[TS_i=TS_c:TS_b] \
(TS_d=((TS_b-TS_i)%3==0&&(TS_i<TS_b)?TS_d.TS_a[TS_i:TS_i].ts:TS_d.TS_a[TS_i:TS_i]),\
0), TS_d)) : sprintf("%g",a)
# settings for (auto-)tics
range(axis) = axis eq "y" ? abs(GPVAL_Y_MAX-GPVAL_Y_MIN) : abs(GPVAL_X_MAX-GPVAL_X_MIN)
power(axis) = 10.**int(sprintf("%.15e",range(axis))[strstrt(sprintf("%.15e",range(axis)),"e")+1:])
rangenorm(axis) =range(axis)/power(axis)
posns(axis) = 20.0 / rangenorm(axis)
tics(axis) = \
posns(axis)>40?0.05:posns(axis)>20?0.1:posns(axis)>10?0.2:posns(axis)>4? \
0.5:posns(axis)>2?1:posns(axis)>0.5?2:ceil(range(axis))
ticstep(axis) = tics(axis) * power(axis)
set xrange[0:1e6]
set terminal push # save current terminal
set terminal unknown
plot x lc rgb "web-green"
set terminal pop # restore terminal
# set xtics
do for [i=0:ceil(range("x")/ticstep("x"))+1] {
set xtics add (ThousandSeparator(GPVAL_X_MIN+i*ticstep("x"),"'") GPVAL_X_MIN+i*ticstep("x"))
}
# set ytics
do for [i=0:ceil(range("y")/ticstep("y"))+1] {
set ytics add (ThousandSeparator(GPVAL_Y_MIN+i*ticstep("y"),"'") GPVAL_Y_MIN+i*ticstep("y"))
}
replot
### end of code
Limitations:
if the begin of the axis (e.g. GPVAL_X_MIN) is not identical with the first tic label, the above procedure doesn't work (yet).
However, I haven't yet found the value which gnuplot sets as first tic value. There seems to be no GPVAL_... variable for this. Maybe it can be extracted somehow?
Example 1: (works ok)
set xrange[0:1e6]
Example 2: (doesn't work, because GPVAL_X_MIN=-50000 but first tic should be at 0)
set xrange[-50000:1e6]

Related

How to define custom character with code > 126 using ESC/POS commands?

I'm trying to define custom characters on thermal printer NCR 7199.
I used ESC/POS command
ESC & y c1 c2 x d1...dn
and it works fine. But this command can change only characters in range 32-126, and those characters are latin letters and common symbols.
I'd prefer to replace characters with codes 8E-8F, for example, but cannot do it using this command.
Is it possible? Or is there any other ESC/POS command for user-defined characters?
UPD.
It seems like a firmware update can fix this problem. Firmware version on our printer is v99.21, and I saw this in release notes:
v99.25 "based on v99.24"
1. Allowed User-defined characters defined range from 20H to FFH in 7199 Emulation mode
Another user-defined character setting command for Kanji is for printers that support the MBCS character set, which is not what you want.
FS 2
Define user-defined Kanji characters
However, although it is unclear whether NCR 7199 supports it, ESC/POS has the ability to customize the font of the user-defined code page rather than the individual characters.
Please refer to the contents of the following pages.
GS ( E <Function 7>
Copy the user-defined page
GS ( E <Function 8>
Define the data (column format) for the character code page
GS ( E <Function 9>
Define the data (raster format) for the character code page
GS ( E <Function 10>
Delete the data for the character code page
Problem solved by updating firmware.
After updating "Main Firmware" to v99.27 (it seems that version must be greater or equal v99.25) and changing Emulation mode to "NCR 7199" I was finally able to define characters in all range 20-FF.

ZPL command barcode 3 zeros creates issues

I am trying to print to a GT800 Zebra printer thru serial port.
I am using ZPL. I want to control the width which is fine in auto mode. To address that in the >^BC> command I am using Auto mode as no other size setting under ^BY works
Following is the code
^XA
^MMT
^PW831
^LL400
^LS0
^BY2,,76^FT225,141^BCN,76,Y,Y,N,A
^FD:RNIP29200082034^FS
^FO225,157^A#N,18,10,E:CAL002.FNT^FD26030-0892R^FS
^FO383,157^A#N,18,10,E:CAL002.FNT^FD08.01.20 12:00PM^FS
^FO225,187^A#N,18,10,E:CAL002.FNT^FDLAMP-DR RH^FS
^FO453,187^A#N,18,10,E:CAL002.FNT^FDXBA3^FS
^PQ1,0,0,Y
^XZ
There is a funny problem. If the ^BC mode = A then if three zeros come together gives issues for eg ABCD29200082034 it prints ABCD29200 and does not complete the barcode. But the other lines are getting printed. But if the data is ABCD29200182034 , there are no issues.
If BC mode = U then even if the code is ABCD29200182034 it prints 292001820347. Note 7 is added in the end.
I am clueless as to what is this issue. I remember facing this same issue in Honeywell printer too once.
Thanks
NOTE : I replaced the 000 with 111 and the problem persists.
ZPL Manual says the following
A= Automatic Mode :This analyzes the data sent and automatically determines the best packing method. The full ASCII character set can be used in the ^FD
statement — the printer determines when to shift subsets. A string of
four or more numeric digits causes an automatic shift to Subset C.
Note , it says a string of four or more numeric digits causes an automatic shift to subset C, but when the same string is 290010 it has no issues. I am really lost

How to get a dot over a symbol in gnuplot?

I am trying to create a plot in gnuplot with dots over the symbol theta in legend.
I am looking to do something similar to, \dot{\theta} and \ddot{\theta} from latex. However, most posts ask to use 'set term latex' or 'set term epslatex' which outputs a .tex file. I need to keep the output as a pdf with the dot and double dot over the theta in the legend. Is this possible? Appreciate any help. Thanks!
In place of 'Pitch rate', I need the symbol theta with a dot above it.
In place of 'Pitch acceleration', I need the symbol theta with two dots above it.
set term pdf
set termopt enhanced
set encoding utf8
set output "rampfuncs.pdf"
set style func linespoints
set xlabel 'time'
set format y "%.2f"
plot "output.dat" using 1:2 title '{/Symbol q} - Pitch angle', \
"output.dat" using 1:3 title 'Pitch rate', \
"output.dat" using 1:4 title 'Pitch acceleration'
set term x11
Update after answer from meuh: Image for reference
Second update after comments from meuh: Image 2
This is described in the section Enhanced text mode of the gnuplot guide. You can use the ~ tilde character to overprint two items, for example ~a/ will overprint a and /. In your case you need to raise the dot character by 1.1 times the font size (found empirically) in order for it to appear above the a so you prefix the character with this number, and enclose it in braces to make it one item: ~a{1.1.}
plot "data" using 1:2 title '{/Symbol q} angle', \
"data" using 1:3 title '~{/Symbol q}{1.1.} rate', \
"data" using 1:4 title '~{/Symbol q}{1.1..} accel'
which gives this result:
There seems to be a bug where the title will not be shown correctly if the ~{}{} construct is at the end of the title. The simple workaround is to add an extra space at the end of the title ~{}{} .

how to tokenize/parse/search&replace document by font AND font style in LibreOffice Writer?

I need to update a bilingual dictionary written in Writer by first parsing all entries into their parts e.g.
main word (font 1, bold)
foreign equivalent transliterated (font 1, italic)
foreign equivalent (font 2, bold)
part of speech (font 1, italic)
Each line of the document is the main word followed by the parts listed above, each separated by a space or punctuation.
I need to automate the process of walking through the whole file, line by line, and place a delimiter between each part, ignoring spaces and punctuation, so I can mass import it into a Calc file. In other words, "each part" is a sequence of character (ignoring spaces and punctuation) that have the same font AND font-style.
I have tried the standard Search&Replace feature, and AltSearch extension, but neither are able to complete the task. The main problem is I am not able to write a search query that says:
Find: consecutive characters with the same font AND font_style, ignore spaces and punctuation
Replace: term found above + "delimiter"
Any suggestions how I can write a script for this, or if an existing tool can solve the problem?
Thanks!
Pseudo code for desired effect:
var delimiter = "|"
Go to beginning of document
While not end of document do:
var $currLine = get line from doc
var $currChar = get next character which is not space or punctuation;
var $font = currChar.font
var $font_style - currChar.font_style (e.g. bold, italic, normal)
While not end of line do:
$currChar = next character which is not space or punctuation;
if (currChar.font != $font || currChar.font_style != $font_style) { // font or style has changed
print $delimiter
$font = currChar.font
$font_style - currChar.font_style (e.g. bold, italic, normal)
}
end While
end While
Here are tips for each of the things your pseudocode does.
First, the easiest way to move line by line is with the TextViewCursor, although it is slow. Notice the XLineCursor section. For the while loop, oVC.goDown() will return false when the end of the document is reached. (oVC is our variable for the TextViewCursor).
Get each character by calling oVC.goRight(0, False) to deselect followed by oVC.goRight(1, True) to select. Then the selected value is obtained by oVC.getString(). To ignore space and punctuation, perhaps use python's isalnum() or the re module.
To determine the font of the character, call oVC.getPropertyValue(attr). Values for attr could simply be CharAutoStyleName and CharStyleName to check for any changes in formatting.
Or grab a list of specific properties such as 'CharFontFamily', 'CharFontFamilyAsian', 'CharFontFamilyComplex', 'CharFontPitch', 'CharFontPitchAsian' etc. Character properties are described at https://wiki.openoffice.org/wiki/Documentation/DevGuide/Text/Formatting.
To insert the delimiter into the text: oVC.getText().insertString(oVC, "|", 0).
This python code from github shows how to do most of these things, although you'll need to read through it to find the relevant parts.
Alternatively, instead of using the LibreOffice API, unzip the .odt file and parse content.xml with a script.

OpenTsdb: Is Space character allowed in Metric and tag information

I was working with openTsdb and came across with the issue that space character is not allowed in metric, tag(tagk) and even the values(tagv). Is there any way we can add space atleast in the value of tag?
I also referred: http://opentsdb.net/docs/build/html/user_guide/writing/index.html#metrics-and-tags
As of opentsdb version 2.3 there is support for specifying additional characters to allow via the config variable
tsd.core.tag.allow_specialchars = !##$%^&*()_+{}|: <>?~`-=[]\;',./°
http://opentsdb.net/docs/build/html/user_guide/configuration.html gives more details
Spaces are not allowed.
As per the documentation you referred:
Only the following characters are allowed: a to z, A to Z, 0 to 9, -, _, ., / or Unicode letters (as per the specification)
I suggest you should use '_' in stead of spaces.

Resources