To format my output, I would like to add thousand separators to my x and y axis. My data are 'regular' english format (e.g. 3.141 is approximately pi and not three thousand, so "." is the decimal separator) , but for my graph, I would like to use german formatting.
It is possible to change the formatting using
set decimalsign locale 'de_DE.utf8'
set decimalsign "."
set format "%'.0f"
but this results in the values being read wrong (e.g. 3.141 is just read as 3, since the german locale with "," as decimal separator is used).
Using
set decimalsign locale 'en_GB.utf8'
set decimalsign "."
set format "%'.0f"
fixes the wrong values, but uses "," as thousand separator (instead ".").
Is it possible to keep the data clean and just tell gnuplot to use a different thousand separator for displaying?
If I understand correctly, the only command needed is
set decimalsign ","
, although it is possible there is further interaction with the locale settings of the machine you run it on. For me, this produces the attached figure:Thanks for the quick reply.
This works for the decimalsign, but not for the thousand separator.
If I change your example to
than the thousand separator is not displayed correctly (it should be
1.000,0
, but is1000,0
, example.png).If I now change the locale and decimalsign, the x axis is correct, but the values are wrong:
(example_wrongValues.png).
Do you see any option to get the thousand separator working correctly and preserving the reading of the values with dot as decimal separator?
Last edit: David Georg Reichelt 2022-04-07
No, sorry.
Gnuplot's internal formatting routine does not know anything about the locale properties LC_NUMERIC:thousands_sep or LC_NUMERIC:grouping. It does not implement anything equivalent to the C language (POSIX 2008, SUSv3) single-quote format flag character.
I'm not sure exactly what happens when you use it anyhow, as in your
set format
command. It appears that the properties of the current locale setting bleed through. I suppose that is a bug, since it is clearly incorrect to have both the thousands separator and the decimal point end up being the same character.Work-around:
You can do this in two stages. First read in the data and save it to a temporary data block that converts the decimal point character. Second, switch fully to the German locale and plot from the temporary copy of the data. I don't have German locales installed here, but I think this should work the same way:
Thanks, your workaround works fine when having the data directly in the script.
Is it also possible to import the data somehow, and plot them later? If I use a
plot
command on a CSV file, loading and plotting happens at the same time from my point of view. One workaround would be to write the data directly into the script, but that would be equally cumbersome as transforming the data to my locale.It seems like the load command (http://gnuplot.sourceforge.net/docs_4.2/node97.html) could do this somehow, but
$DATA << load 'myData.csv'
did not work and I did not find other documentation on the usage of the load command.The temporary table is created by
set table $TEMP; plot ...; unset table
. The data source for theplot
command was included in the script for the purpose of showing an example, but it could equally well be a csv file.Thanks for the hint, but unfortunately, I did not manage to get this running.
If I've got a data file that contains
and a plot script
than this script will only plot a horizontal line (test1.pdf). If I leave out the
set decimalsign
command, the graph is plotted as expected (test2.pdf).It seems like gnuplot even does something with the values after the data are loaded. Is there maybe a workaround for this?
You left out a command. The idea of the first step is to change the decimal character from period (as it is in data.csv) to comma (to be stored in $TEMP). So you need a command
set decimalsign ','
prior to filling $TEMP.The load commnad is for loading a sciprt file but not data.
Use just "plot datafile" but not "plot $datablock".
For CSV file, data separator should set to comma
Use "set datafile separator commna".
For detail
gnuplot> help set datafile separator
Last edit: Tatsuro MATSUOKA 2022-04-08
@tmacchant3 Unfortunately, as explained earlier, just using
plot datafile
is not possible since the data contain dot as decimal separator (so their locale is suitable foren_GB.utf8
), but the axis should contain dot as thousand separator and comma as decimal separator (like inde_DE.utf8
). Since this cannot be achieved in one step, loading the data and plotting them needs to be split.Ticket moved from /p/gnuplot/bugs/2517/
Can't be converted: