2

I have incomplete test data, as shown in the MWE. I would like to use all (few) available data points in the plot, ie (55.16, 0.08) for copper, but the plot does not take it into account. Also the global options such as the comma delimiter do not work (it works only for the native y =0.5 y tick label, but not for the added y tick labels. (they however work fine with one of the plots from the manual, therefore the problem is with my data and/or plot options. I have also been unable to use in the plot the option "only marks" which would probably make sense.

\documentclass[]{scrartcl}
\usepackage{siunitx}
\usepackage{filecontents}
\usepackage{pgfplots}
\usepackage{pgfplotstable}


\pgfplotsset{compat=newest,
every linear axis/.append style={
/pgf/number format/use comma,
/pgf/number format/fixed,
}}

\begin{document}

\begin{filecontents}{data-W.csv}
{Stress};{Aluminium};{Copper}
3.44;0.0015;0.001
6.89;0.1;0.002
10.34;0.2; 
11.72; ;0.0068
13.79; ; 
15.51;0.5; 
17.24; ; 
20.68;1;0.01
24.13; ; 
27.58; ; 
31.03; ; 
34.47; ;
37.92; ; 
41.37; ;0.04
44.82; ; 
48.26; ; 
55.16; ;0.08
\end{filecontents}

\pgfplotstableread[col sep=semicolon]{data-W.csv}{\datatableW}

\begin{tikzpicture}
\begin{axis}[
height=.5\textwidth, width=\textwidth,
xticklabel style= {font={\small}},
grid=both,
%xticklabels from table={\datatableW}{[index]0}, %does not accept plot settings
 extra y ticks={.1,.3,.5,.7,.9},  % Did not accept global option but now does
%extra y tick labels={.1,.3,.5,.7,.9} % not necessary now
xlabel={Stress (\si{\mega\pascal})}, 
ylabel={Relaxation (\%)}, 
legend entries={Pure aluminium,Copper}, ]
\addplot [blue,only marks]  table [ 
x index =0, y index=1] {\datatableW};
% x expr=\coordindex, x index =0,{\datatableW}; % Incorrect
\addplot [red,]  table [
x index =0, 
%x expr=\coordindex, x index =0, % incorrect
y index=2] {\datatableW}; 
\end{axis} \end{tikzpicture}

\end{document}
  • Try removing xticklabels from table={\datatableW}{[index]0},. – user11232 Aug 1 '15 at 8:33
  • If I remove the "xticklabels from...", as suggested, the x tick labels are replaced by 0, 2 , 4, 6, etc, and have no longer a relation with the values. I have found however that deleting from my data file the lines where there is no value in any of the y columns, makes the plot include the max x values, but still the plot labels do not align with the desired format for numbers... – Yves Aug 1 '15 at 11:49
  • Why do you need to add extra tick labels for the y axis? If you don't do that, you get the expected format (for the y axis) and you do not get the .75 mark being erroneously labelled as .5 in addition to the .5 mark being properly labelled as .5. However, you need to include the leading zeros to trigger the formatting of the decimal separator, I think. – cfr Aug 2 '15 at 1:34
  • I've fiddled with this and I can things prettily printed as a table. But I can't really find anything in the documentation which explains how to combine pgfplotstable with pgfplots. The documentation is... leaves something to be desired. It is more like the TikZ/PGF manual than even the TikZ/PGF manual! – cfr Aug 2 '15 at 2:54
  • The manual of pgfplotstable indicates on page 55 that the section related to plotting data was moved to the pgfplots manual, but provides however an example. The pgfplots manual shows a few examples dealing with this topic as of page 26. – Yves Aug 2 '15 at 12:13
1

There were several mistakes in the plot options (and contradictions in the general plot settings) that created the problems. I have edited the code to highlight and correct them. It is still unclear to me why the option

xticklabels from  table={\datatableW}{[index]0}

does not seem to accept the global plot settings, but removing it makes the plot more ordinary and better looking, more logical.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.