I am trying to do the following:
- Read data from a file [CSV]
- Add a calculated row to it [C]
- Transpose the data
- Plot the data
- Display the data in a table
Everything works so far, but the calculated row, and only the calculated row, is written in a scientific number format, althoug there is no reason for it (at least I don't see a clear reason why pgfplotstable should do it ...). I am trying to get rid of the scientific numbers to either get floating numbers or simple integers (as there will be no decimal place).
I have the following minimal working example:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Preamble
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Use A4 paper
\documentclass[a4paper]{article}
% Use english language
\usepackage[english]{babel}
% Use UTF8 encoding
\usepackage[utf8]{inputenc}
% TikZ and PGF libraries for graphs
\usepackage{tikz}
\usepackage{pgfplots, pgfplotstable}
% Booktabs for layout of tables
\usepackage{booktabs}
% Enable library for date-plotting
\usetikzlibrary{pgfplots.dateplot}
% Enable library for statistics [boxplot]
\usepgfplotslibrary{statistics}
% Always use newest version
\pgfplotsset{compat=newest,compat/show suggested version=false}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Pre - Document
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Create data to test
\begin{filecontents}{testData.csv}
day, A, B
01, 10, 5
02, 20, 10
03, 100, 5
\end{filecontents}
% Create 'C' by calculating 'A - B'
\pgfplotstableset{
create on use/C/.style={
create col/expr={\thisrow{A}-\thisrow{B}},
}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Document
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
%%% Setup
% Read data and save it to 'dataTable'
\pgfplotstableread[
col sep=comma,
]{testData.csv}\dataTable
% Create second, in memory, table, that transposes the table, so that on the left side are the labels, followed by corresponding numbers, ordered by the date.
% Save it to 'dataTransposed'
\pgfplotstabletranspose[
col sep=comma,
string type,
colnames from=day,
input colnames to=day,
columns={day, A, B, C}
]\dataTransposed{\dataTable}
%%% Visualizing data
% Plot data from 'dataTable'
\begin{tikzpicture}
\begin{axis}[
width=\textwidth,
height=\axisdefaultheight,
xmin=01,
xmax=31,
ymin=0,
ymax=180,
xtick=data,
xticklabel style={
rotate=90,
anchor=near xticklabel,
},
transpose legend,
legend style={at={(0.5,-0.1)},anchor=north},
legend columns=-1,
]
\addplot table [col sep=comma,x=day,y=A] {\dataTable};
\addplot table [col sep=comma,x=day,y=B] {\dataTable};
\addplot table [col sep=comma,x=day,y=C] {\dataTable}; % the generated data
\legend{A, B, C}
\end{axis}
\end{tikzpicture}
% Create tables from 'dataTransposed'
\begin{center} % Center table
\pgfplotstabletypeset[
col sep=comma,
string type,
% columns={day, 01, 02, 03, 04, 05, 06, 07, 08, 09, 10},
every head row/.style={
before row=\toprule,
after row=\midrule
},
every last row/.style={
after row=\bottomrule
}
]{\dataTransposed}
\end{center}
\end{document}
Which produces the following output:
As we can see the 'C' row is displayed in scientific numbers. How can I change that?
I've already tried to set the number format with:
\pgfkeys{/pgf/number format/int trunc}
[Within the preamble, document, before the table, before the data read etc.; Also as an argument within square brackets] Which did nothing?
Interestingly
\pgfmathprintnumber{5}
prints the number in the right number format, even without setting anything.
Thanks in advance.
\sisetup{ round-mode = places, round-precision = 2, per-mode = symbol, group-four-digits = true, } \SendSettingsToPgf
string type
withcolumns/day/.style={string type}
.