2

I'm trying to plot some data that I aquired form a sensor. However, the plot looks very messed up an I'm not sure why. It appears as if the data on the x axis is not read correctly.

MWE:

\documentclass[]{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.14}

\begin{document}

\begin{figure}
    \pgfkeys{/pgf/number format/.cd,1000 sep={}}
    \centering

    \begin{tikzpicture}[thick,scale=0.9, every node/.style={scale=0.9}]
    \begin{axis}[width=\textwidth, height = 4cm,
    enlarge x limits=0.05,
    enlarge y limits=0.05,
    axis y line*=left,
    ylabel near ticks,
    ticklabel style = {font=\small, /pgf/number format/fixed},
    ]

    \addplot[blue, mark=o, mark size=0.5] table [col sep= semicolon,x expr=\thisrowno{0},y expr=\thisrowno{1}] {figs/csv/testdata.csv};
    \end{axis}  
    \end{tikzpicture}
\end{figure}
\end{document}

Data

0;0;0;
0.071629883;0;0;
0.120055664;0;0;
0.160855957;0;0;
0.209806641;0;0;
0.260736084;0;0.000036;
0.310104248;0;0.000036;
0.360027588;0;0.000036;
0.420015869;0;0.000036;
0.472098144;0;0.000036;
0.521723877;0;0.000036;
0.560094482;0;0.000036;
0.609779541;0;0.000036;
1.680107422;0;0.000072;
1.71967749;0;0.000072;
1.771094238;0;0.000072;
1.820157715;0;0.000072;
1.872039551;0.000036;0.000144;
1.9099021;0.000036;0.000144;
1.959828857;0.000036;0.000144;
2.009779297;0.000036;0.000144;
2.070414551;0.000036;0.000144;
2.119685547;0.000036;0.000144;
2.170467285;0.000036;0.000144;
2.220720947;0.000036;0.000144;
2.272105713;0.000072;0.000144;
2.310694336;0.000072;0.000144;
2.379699219;0.000072;0.000144;
2.430689209;0.000072;0.000144;
2.469827148;0.000036;0.00018;
2.541799316;0.000036;0.00018;
2.570321045;0.000036;0.00018;
2.631230957;0.000036;0.00018;
3.672263916;0.000036;0.000144;
3.732255615;0.000036;0.000144;
3.782145264;0.000036;0.000144;
3.822435791;0.000036;0.000144;
3.870311523;0.000036;0.00018;
3.920929199;0.000036;0.00018;
3.970311523;0.000036;0.00018;
4.031988281;0.000036;0.00018;
4.079796387;0.000036;0.00018;
4.133641357;0.000036;0.00018;
4.182786133;0.000036;0.00018;
4.232314941;0.000036;0.00018;
4.270384033;0.000108;0.000216;
4.340993408;0.000108;0.000216;
4.389754639;0.000108;0.000216;
4.431398926;0.000108;0.000216;
4.480282715;0.000072;0.000216;
4.532015137;0.000072;0.000216;
4.581333252;0.000072;0.000216;
4.641760254;0.000072;0.000216;
5.670248535;0.000072;0.000216;
1.444755127;0.000072;0.000216;
1.496422852;0.000072;0.000216;
1.537563477;0.000072;0.000216;
1.587568359;0.000108;0.000252;
1.636967773;0.000108;0.000252;
1.6965354;0.000108;0.000252;
1.747531738;0.000108;0.000252;
1.794815185;0.000108;0.000252;
1.844855469;0.000108;0.000252;
1.894973144;0.000108;0.000252;
1.954683594;0.000108;0.000252;
2.004863525;0.000072;0.000252;
2.055058838;0.000072;0.000252;
2.095244873;0.000072;0.000252;
2.145285889;0.000072;0.000252;
2.196025391;0.000072;0.000216;
2.245090332;0.000072;0.000216;
2.305351807;0.000072;0.000216;
2.354937988;0.000072;0.000216;
3.404730713;0.000108;0.000288;
3.446377197;0.000108;0.000288;
3.495988281;0.000108;0.000288;
3.545875732;0.000108;0.000288;
3.614824951;0.000108;0.000324;
3.654865723;0.000108;0.000324;
3.705044189;0.000108;0.000324;
3.75513208;0.000108;0.000288;
3.805130127;0.000108;0.000288;
3.855437256;0.000108;0.000288;
3.916740234;0.000108;0.000288;
3.964783203;0.000108;0.000324;
4.004787842;0.000108;0.000324;
4.054863037;0.000108;0.000324;
4.104841553;0.000108;0.000324;
4.155813477;0.000108;0.000324;
4.214694092;0.000108;0.000324;
4.26530542;0.000108;0.000324;
4.316487793;0.000108;0.000324;
5.365537842;0.000144;0.00036;
5.406313477;0.000144;0.00036;
5.455348389;0.000144;0.00036;
5.504682861;0.000144;0.00036;
5.564702393;0.000144;0.00036;
5.615235352;0.000108;0.000396;
5.66501709;0.000108;0.000396;
5.716272461;0.000108;0.000396;
5.765105957;0.000144;0.000468;
5.804882813;0.000144;0.000468;
5.854843018;0.000144;0.000468;
5.904821045;0.000144;0.000468;
5.964878906;0.000144;0.000504;
6.016854736;0.000144;0.000504;
6.084712158;0.000144;0.000504;
6.114974609;0.000144;0.000504;
6.157292236;0.000144;0.00054;
6.204788818;0.000144;0.00054;
6.275207275;0.000144;0.00054;
6.324762939;0.000144;0.00054;
7.364826904;0.000144;0.000648;
7.417193604;0.000144;0.000648;
7.464861084;0.000144;0.000648;
7.514973389;0.000144;0.000648;
7.575866211;0.000144;0.000684;
7.624683838;0.000144;0.000684;
7.675487305;0.000144;0.000684;
7.725528076;0.000144;0.000684;
7.764833496;0.00018;0.000792;
7.814776611;0.00018;0.000792;
7.884691894;0.00018;0.000792;
7.925552002;0.00018;0.000792;
7.97732959;0.000144;0.000828;
8.025930664;0.000144;0.000828;
8.076083252;0.000144;0.000828;
8.125166504;0.000144;0.000828;
8.16506543;0.000144;0.000864;
8.23674292;0.000144;0.000864;
8.286797119;0.000144;0.000864;
8.324742676;0.000144;0.000864;
9.374735352;0.000144;0.000936;
9.426908691;0.000144;0.000936;
9.476262695;0.000144;0.000936;
9.53762085;0.000144;0.000936;
9.58681958;0.000144;0.000972;
9.636618408;0.000144;0.000972;
9.675132324;0.000144;0.000972;
5.429856934;0.000144;0.000972;
5.480016113;0.000144;0.001008;
5.541055176;0.000144;0.001008;
5.58253125;0.000144;0.001008;
5.642254639;0.000144;0.001008;
5.689692871;0.000108;0.001008;
5.742839111;0.000108;0.001008;
5.779823486;0.000108;0.001008;
5.83035498;0.000108;0.001008;
5.902074219;0.000144;0.00108;
5.940004639;0.000144;0.00108;
5.989817627;0.000144;0.00108;
6.040050781;0.000144;0.00108;
7.089841064;0.000144;0.001116;
7.152619873;0.000144;0.001116;
7.182628174;0.000144;0.001116;
7.249715332;0.000144;0.001116;
7.291754639;0.00018;0.001188;
7.342202148;0.00018;0.001188;
7.392263428;0.00018;0.001188;
7.44006543;0.00018;0.001188;
7.490038086;0.00018;0.001188;
7.550145996;0.00018;0.001188;
7.599801269;0.00018;0.001188;
7.649716553;0.00018;0.001188;
7.701636719;0.000216;0.00126;
7.742176269;0.000216;0.00126;
7.810155762;0.000216;0.00126;
7.840539551;0.000216;0.00126;
7.899704102;0.000252;0.001332;
7.949872559;0.000252;0.001332;
8.000241211;0.000252;0.001332;
8.049711182;0.000252;0.001332;
9.099890869;0.000216;0.001332;
9.160033935;0.000216;0.001332;
9.189873291;0.000216;0.001332;
9.259968506;0.000252;0.001368;
9.300023926;0.000252;0.001368;
9.34996582;0.000252;0.001368;
9.400230469;0.000252;0.001368;
9.460027588;0.000288;0.00144;
9.509937012;0.000288;0.00144;
9.560848633;0.000288;0.00144;
9.610237305;0.000288;0.00144;
9.650707031;0.000252;0.001476;
9.700744141;0.000252;0.001476;
9.749695313;0.000252;0.001476;
9.819953857;0.000252;0.001476;
9.859970947;0.000252;0.001476;
9.909832764;0.000288;0.001512;
9.959778564;0.000288;0.001512;
10.00993799;0.000288;0.001512;
10.05167212;0.000288;0.001512;
11.10002002;0.000288;0.001548;
11.17000073;0.000288;0.001548;
11.22003979;0.000288;0.001548;
11.25980811;0.000288;0.001584;
11.30994482;0.000288;0.001584;
11.36169189;0.000288;0.001584;
11.41014526;0.000288;0.001584;
11.45984912;0.000288;0.00162;
11.5211062;0.000288;0.00162;
11.57000537;0.000288;0.00162;
11.61987695;0.000288;0.00162;
11.65994067;0.000324;0.001692;
11.70985107;0.000324;0.001692;
11.78008032;0.000324;0.001692;
11.82004614;0.000324;0.001692;
11.87197241;0.000324;0.001728;
11.91997925;0.000324;0.001728;
11.9801333;0.000324;0.001728;
12.00993726;0.000324;0.001728;
12.06028564;0.000324;0.001764;
13.10997827;0.000324;0.001764;
13.16993384;0.000324;0.001764;
13.21993848;0.000324;0.001764;
13.27024512;0.000288;0.001764;
13.3197312;0.000288;0.001764;
13.38073975;0.000288;0.001764;
13.40991919;0.000288;0.001764;
13.47985791;0.000324;0.001764;
13.53198145;0.000324;0.001764;
13.56968384;0.000324;0.001764;
13.61973975;0.000324;0.001764;
13.67010474;0.000288;0.001836;
9.425856445;0.000288;0.001836;
9.485707764;0.000288;0.001836;
9.53709668;0.000288;0.001836;
9.585488769;0.000288;0.001872;
9.635101074;0.000288;0.001872;
9.674904785;0.000288;0.001872;
9.745071045;0.000288;0.001872;
10.77510645;0.000252;0.001872;
10.83488257;0.000252;0.001872;
10.88657544;0.000252;0.001872;
10.93610449;0.000252;0.001872;
10.98601172;0.000252;0.001872;
11.03603296;0.000252;0.001872;
11.07518335;0.000252;0.001872;
11.14502441;0.000252;0.001872;
11.19488452;0.000252;0.001908;
11.23689648;0.000252;0.001908;
11.2858999;0.000252;0.001908;
11.33555029;0.000252;0.001908;
11.38492651;0.000252;0.001944;
11.44757007;0.000252;0.001944;
11.49712158;0.000252;0.001944;
11.5450896;0.000252;0.001944;
11.59492847;0.000216;0.001908;
11.63481128;0.000216;0.001908;
11.68626611;0.000216;0.001908;
11.74663647;0.000216;0.001908;
12.79508618;0.000216;0.001944;
12.84515894;0.000216;0.001944;
12.89573608;0.000216;0.001944;
12.94668994;0.000216;0.001944;
12.98544238;0.000216;0.001908;
13.05491016;0.000216;0.001908;
13.10491479;0.000216;0.001908;
13.14538647;0.000216;0.001908;
13.19498682;0.000216;0.001944;
13.24599023;0.000216;0.001944;
13.31514502;0.000216;0.001944;
13.35484326;0.000216;0.00198;
13.40528711;0.000216;0.00198;
13.45480347;0.000216;0.00198;
13.50520557;0.000216;0.00198;
13.55560132;0.000216;0.001944;
13.61533789;0.000216;0.001944;
13.66495752;0.000216;0.001944;
13.72490527;0.000216;0.001944;
13.75479321;0.000216;0.001944;
14.80586377;0.000216;0.001944;
14.87480103;0.000216;0.001944;
14.91498608;0.000216;0.001944;
14.96479541;0.00018;0.001908;
15.01475562;0.00018;0.001908;
15.06480103;0.00018;0.001908;
15.12511426;0.00018;0.001908;
15.15493213;0.00018;0.001908;
15.22520044;0.000216;0.001944;
15.26487402;0.000216;0.001944;
15.31484888;0.000216;0.001944;
15.36521582;0.00018;0.001908;
15.41484717;0.00018;0.001908;
15.47508154;0.00018;0.001908;
15.52505664;0.00018;0.001908;
15.57494751;0.00018;0.001944;
15.62520166;0.00018;0.001944;
15.66499072;0.00018;0.001944;
15.71515601;0.00018;0.001944;
16.78520532;0.000144;0.001872;
16.81519385;0.000144;0.001872;
16.87480957;0.000144;0.001872;
16.92546655;0.000144;0.001872;
16.97491235;0.000144;0.001908;
17.02498975;0.000144;0.001908;
17.06505811;0.000144;0.001908;
17.11473633;0.000144;0.001908;
17.18526489;0.00018;0.001908;
17.22501709;0.00018;0.001908;
17.27488672;0.00018;0.001908;
17.32492334;0.00018;0.001908;
17.3748667;0.000144;0.001944;
17.43476978;0.000144;0.001944;
17.48530249;0.000144;0.001944;
17.5351333;0.000144;0.001944;
17.5760603;0.000144;0.001908;
17.62490503;0.000144;0.001908;
17.67477124;0.000144;0.001908;
13.43029272;0.000144;0.001908;
14.49017114;0.000144;0.001944;
14.54244653;0.000144;0.001944;
14.59251685;0.000144;0.001944;
14.62986206;0.000144;0.001944;
14.68021069;0.000144;0.001908;
14.73250537;0.000144;0.001908;
14.79016016;0.000144;0.001908;
14.84232715;0.000144;0.001908;
14.89018042;0.00018;0.001944;
14.94035889;0.00018;0.001944;
14.98151001;0.00018;0.001944;
15.02983521;0.00018;0.001944;
15.10040039;0.00018;0.001944;
15.15360645;0.00018;0.001944;
15.19078638;0.00018;0.001944;
15.24091675;0.00018;0.001944;
15.29192334;0.000144;0.001944;
15.33987476;0.000144;0.001944;
15.40230298;0.000144;0.001944;
15.45159814;0.000144;0.001944;
16.50028979;0.00018;0.001944;
16.5500752;0.00018;0.001944;
16.59025146;0.00018;0.001944;
16.64055347;0.00018;0.001944;
16.69217358;0.00018;0.00198;
16.75044751;0.00018;0.00198;
16.80260278;0.00018;0.00198;
16.85054932;0.00018;0.00198;
16.90022437;0.00018;0.00198;
16.95377783;0.00018;0.00198;

Output

messed up plot

What's wrong here?

  • Nothing is wrong, the plot shows the data. (Or rather, if the plot is wrong, the data is wrong.) – Torbjørn T. Oct 18 '17 at 9:52
  • Your data are not ordered on first column. Look at them, after 5.6 goes back to 1.4, after 9.6 to 5.4, ... – Ignasi Oct 18 '17 at 11:04
  • ah, I see. Yes, of course, it doesn't order the stuff for me. Thank you for the hint, I didn't notice this. – LoveDaOOP Oct 18 '17 at 13:48
  • You can sort it after you load the data – percusse Oct 18 '17 at 15:53
1

Data is plotted in order of appearance in the csv file - it is not sorted.

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.