1

I'm trying to evaluate the desired and actual path of my robot and draw the error between them. Tikz reduces the y-axis of my plot to zero and i dont know why... here is the code and the result...

\documentclass[12pt]{article}
\usepackage{pgfplots,subcaption}
\usepackage[left=1cm,right=1cm]{geometry}

\pgfplotsset{ compat=1.3,}

\begin{document}
\usetikzlibrary{calc} % a package for coordination alignment and placement


\begin{figure}[!h]\centering
\begin{subfigure}[t]{0.49\textwidth} \centering
\begin{tikzpicture} [baseline]
\begin{axis}[
name=mainplot,
at={($(0cm,0cm)$)},
 y tick label style={
        /pgf/number format/.cd,
            fixed,
            fixed zerofill,
            precision=1,
        /tikz/.cd
    },
     x tick label style={
        /pgf/number format/.cd,
            fixed,
            fixed zerofill,
            precision=1,
        /tikz/.cd
    },
height=9cm,
width=9cm,
enlarge x limits,
enlarge y limits,
   xlabel={$x(m)$},
   ylabel={$y(m)$},    
   zlabel={$z(m)$},
   legend pos = north east,
   view={0}{90},
]
\addplot3[
    smooth,
    color=blue,
    samples=300,
    ]
table [x=x, y=y, z=z]{XD.txt}; 
\addplot3[
    smooth,
    color=red,
    samples=300,
    ]
table [x=x, y=y, z=z]{XE.txt}; 
\legend{Desired,Actual}
\end{axis}
\end{tikzpicture}
\subcaption{Plot 1}\label{fig:ufMna}
\end{subfigure}
%
%
\begin{subfigure}[t]{0.49\textwidth} \centering

\begin{tikzpicture}[baseline]
%
    \begin{axis}[
    name=plot1,
    at={($(15cm,0cm)$)},
    height=3cm,
    width=8cm,
    xlabel=time (s),
    ylabel=$z$ error,
    axis equal image=true,
    grid=major,
    domain=0:50,
    domain y=-5e-3:5e-3,
    ]
 \addplot[black] 
               table [x=t, y=z]{err_x.txt};
    \end{axis}
    %
            \begin{axis}[
    name=plot2,
    at={($(plot1.north)+(0cm,1.5cm)$)},
    anchor=south,
    height=3cm,
    width=8cm,
    xlabel=time (s),
    ylabel=$y$ error,
    name=plot1, 
    axis equal image=true,
    grid=major,
    domain=0:50,
    domain y=-5e-3:5e-3,
    ]
        \addplot[black] 
               table [x=t, y=y]{err_x.txt};
    \end{axis}
%
            \begin{axis}[
    name=plot3,
    at={($(plot1.north)+(0cm,1.5cm)$)},
    anchor=south,
    height=3cm,
    width=8cm,
    xlabel=time (s),
    ylabel=$x$ error,
    name=plot1, 
    axis equal image=true,
    grid=major,
    domain=0:50,
    domain y=-5e-3:5e-3,
    ]
        \addplot[black] 
               table [x=t, y=x]{err_x.txt};
    \end{axis}
    %
\end{tikzpicture}
\subcaption{Plot 2}
%\label{fig:ufMnb}
\end{subfigure}
%\caption{2 Plots}
\label{fig:ufMn}
\end{figure}
\end{document}

enter image description here

my data for right subfigure is like this:

    t    x      y      z
   0.0000    0.0001    0.0002    0.0011
    0.6988   -0.0014    0.0181    0.0025
    1.3802   -0.0040    0.0321    0.0018
    2.0596   -0.0075    0.0310    0.0056
    2.7543   -0.0110    0.0270    0.0004
    3.4536   -0.0137    0.0215   -0.0013
    4.1266   -0.0175    0.0178    0.0021
    4.7996   -0.0207    0.0067   -0.0012
    5.4890   -0.0214    0.0007   -0.0015
    6.1785   -0.0240   -0.0049   -0.0028
    6.7880   -0.0258   -0.0081   -0.0014
    7.4135   -0.0260   -0.0150   -0.0040
    8.0214   -0.0248   -0.0197   -0.0016
    8.6219   -0.0237   -0.0238    0.0049
    9.2381   -0.0214   -0.0262    0.0062
    5.7488   -0.0212   -0.0316   -0.0017
    6.0909   -0.0183   -0.0382    0.0009
    6.4511   -0.0159   -0.0398    0.0036
    6.8085   -0.0139   -0.0457    0.0028
    7.1624   -0.0104   -0.0478    0.0009
    7.5829   -0.0084   -0.0568    0.0063
    8.0034   -0.0031   -0.0582    0.0084
    8.4186    0.0019   -0.0625    0.0073
    8.8229    0.0070   -0.0621    0.0116
    9.2423    0.0098   -0.0612    0.0127
    9.6818    0.0131   -0.0609    0.0146
   10.0845    0.0183   -0.0551    0.0147
   10.4871    0.0217   -0.0539    0.0152
   10.9281    0.0253   -0.0500    0.0204
   11.3341    0.0310   -0.0441    0.0206
   11.7472    0.0355   -0.0416    0.0205
   12.1521    0.0415   -0.0367    0.0210
   12.5419    0.0463   -0.0318    0.0228
   12.9349    0.0513   -0.0277    0.0241
   13.3390    0.0530   -0.0221    0.0218
   13.7424    0.0555   -0.0182    0.0219
   14.1463    0.0564   -0.0125    0.0192
   14.5519    0.0583   -0.0051    0.0247
   14.9529    0.0563   -0.0037    0.0156
   15.3588    0.0568    0.0029    0.0185
   15.7623    0.0563    0.0119    0.0261
   16.1761    0.0530    0.0141    0.0174
   16.5984    0.0490    0.0224    0.0219
   17.0170    0.0443    0.0284    0.0240
   17.4255    0.0408    0.0356    0.0203
   17.8306    0.0344    0.0400    0.0179
   18.2426    0.0274    0.0457    0.0187
   18.6321    0.0219    0.0498    0.0210
   19.0363    0.0181    0.0513    0.0169
   19.4446    0.0134    0.0531    0.0194
   19.8503    0.0086    0.0490    0.0115
   20.2589    0.0053    0.0501    0.0182
   20.6636    0.0015    0.0467    0.0114
   21.0854   -0.0019    0.0435    0.0146
   21.4946   -0.0056    0.0406    0.0099
   21.9323   -0.0092    0.0376    0.0117
   22.3537   -0.0114    0.0301    0.0114
   22.7792   -0.0142    0.0246    0.0104
   23.1852   -0.0178    0.0166    0.0102
   23.5409   -0.0195    0.0062    0.0098
   23.8854   -0.0203    0.0022    0.0055
   24.2267   -0.0197   -0.0021    0.0050
   24.5753   -0.0208   -0.0069    0.0087
   24.9318   -0.0205   -0.0119    0.0043
   25.2800   -0.0188   -0.0155    0.0076
   25.6218   -0.0162   -0.0188    0.0081
   25.9886   -0.0152   -0.0239    0.0117
   26.3287   -0.0126   -0.0265    0.0092
   26.6820   -0.0114   -0.0305    0.0148
   27.0227   -0.0067   -0.0347    0.0169
   27.4418   -0.0052   -0.0421    0.0149
   27.8539   -0.0005   -0.0442    0.0224
   28.2573    0.0027   -0.0502    0.0121
   28.6676    0.0071   -0.0496    0.0167
   29.1041    0.0113   -0.0496    0.0160
   29.5240    0.0171   -0.0466    0.0238
   29.9510    0.0194   -0.0497    0.0202
   30.3887    0.0246   -0.0433    0.0290
   30.8095    0.0291   -0.0399    0.0285
   31.2178    0.0341   -0.0379    0.0272
   31.6391    0.0396   -0.0337    0.0290
   32.0741    0.0455   -0.0308    0.0301
   32.4988    0.0507   -0.0257    0.0269
   32.9190    0.0560   -0.0202    0.0280
   33.3376    0.0593   -0.0138    0.0292
   33.7416    0.0624   -0.0066    0.0346
   34.1786    0.0637   -0.0051    0.0248
   34.5917    0.0632    0.0017    0.0237
   34.9982    0.0627    0.0092    0.0315
   35.4186    0.0618    0.0122    0.0259
   35.8334    0.0601    0.0165    0.0267
   36.2392    0.0577    0.0236    0.0293
   36.6406    0.0549    0.0286    0.0269
   37.0536    0.0500    0.0371    0.0322
   37.4752    0.0382    0.0199   -0.0252
   37.8882    0.0384    0.0466    0.0243
   38.3087    0.0317    0.0546    0.0288
   38.7457    0.0265    0.0585    0.0299
   39.1616    0.0216    0.0585    0.0222
   39.5845    0.0216    0.0585    0.0222
   40.2620    0.0216    0.0585    0.0222
   41.1949    0.0216    0.0585    0.0222
   42.3832    0.0216    0.0585    0.0222
   43.8270    0.0216    0.0585    0.0222
   45.5263    0.0216    0.0585    0.0222

Thanks in advance!

2

You are using the key axis equal image. This ensures the same axis range for the x- and y-axis. Since your data in the y-axis has a very different magnitude than your x-data, this squeezes the axis together. Compare this to the use of the key axis equal: Plot with axis equal As you can see, this also squeezes the axis together, but keeps the size of the plot.

The solution is simple: just don't use the any axis equal key. Why did you do that in first hand anyway? Plot without axis equal key

As advise: please consider improving your examples in future. While you code is compilable as-is (which is nice), you don't provide all the data, so i had to get rid of the first plot. You mention this, but why not just leave out the first plot? It helps the people helping you.

  • ~ Thanks it worked! sure i will do as you said to help myself and take the less of other guys time :) As you see i have used article class. I used to work with "standalone" class but as i was not able to use "figure" environment in that class. How can i cut useless blank space in this doc now? – Masoud Dec 3 '16 at 12:05
  • @Masoud Try with pdfcrop filename.pdf in a terminal/command line. – Torbjørn T. Dec 3 '16 at 15:53

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.