4

So I wanted to create graphs in my document (which I created in Matlab for simplicity reasons and exported using matlab2tikz) that have the same formatting, fonts etc. as the main text in my document.

matlab2tikz creates this code which draws the graph using tables. The problem is that the graph is a piecewise defined function and where two parts of the graph meet there is this "gap" which I want to get rid of.

I tried using miter, but unfortunately I wasn't able to get it to work.

Does someone has a hint for me?

Adding a MWE:

    \documentclass[11pt]{scrartcl}
    \usepackage[utf8x]{inputenc}
    \usepackage{amsmath}
    \usepackage{graphicx}
    \usepackage{lmodern}
    \usepackage{mathtools}
    \usepackage{amsfonts}
    \usepackage{tikz}
    \usepackage{pgfplots}

    \begin{document}


    \begin{figure}

    % This file was created by matlab2tikz.
    %
    \begin{tikzpicture}[%
    line join = miter
    ]

    \begin{axis}[%
    width=0.856\textwidth,
    height=0.54\textwidth,
    at={(0\textwidth,0\textwidth)},
    scale only axis,
    xmin=0,
    xmax=4,
    xlabel style={font=\color{white!15!black}},
    xlabel={Periodo $T\,[s]$},
    ymin=0,
    ymax=0.09,
    ylabel style={font=\color{white!15!black}},
    ylabel={$S_d\,[g]$},
    axis background/.style={fill=white},
    axis x line*=bottom,
    axis y line*=left,
    scaled y ticks = false,
    y tick label style={/pgf/number format/.cd, fixed, fixed zerofill,precision=2, /tikz/.cd}
    ]
    \addplot [color=black, line width=1.0pt, forget plot]
      table[row sep=crcr]{%
    0   0.036\\
    0.0109  0.0411876\\
    0.0218  0.0463752\\
    0.0327  0.0515628\\
    0.0436  0.0567504\\
    0.0545  0.061938\\
    0.0654  0.0671256\\
    0.0763  0.0723132\\
    0.0872  0.0775008\\
    0.0981  0.0826884\\
    0.109   0.087876\\
    };
    \addplot [color=black, line width=1.0pt, forget plot]
      table[row sep=crcr]{%
    0.109   0.087876\\
    0.327   0.087876\\
    };
    \addplot [color=black, line width=1.0pt, forget plot]
      table[row sep=crcr]{%
    0.327   0.087876\\
    0.3967  0.0724362288883287\\
    0.4664  0.0616111749571183\\
    0.5361  0.0536009177392277\\
    0.6058  0.0474338923737207\\
    0.6755  0.0425395292376018\\
    0.7452  0.0385607246376811\\
    0.8149  0.0352625500061357\\
    0.8846  0.0324841193759891\\
    0.9543  0.0301115498270984\\
    1.024   0.02806196484375\\
    1.0937  0.0262736143366554\\
    1.1634  0.0246995461578133\\
    1.2331  0.0233034238910064\\
    1.3028  0.0220566871354007\\
    1.3725  0.0209365770491803\\
    1.4422  0.0199247344335044\\
    1.5119  0.0190061855942853\\
    1.5816  0.0181685963581184\\
    1.6513  0.0174017150124145\\
    1.721   0.0166969506101104\\
    };
    \addplot [color=black, line width=1.0pt, forget plot]
      table[row sep=crcr]{%
    1.721   0.0166969506101104\\
    1.83599380839719    0.0146708906007282\\
    1.95098761679437    0.0129924147965453\\
    2.06598142519156    0.0115863349149064\\
    2.18097523358874    0.0103967460331488\\
    2.29596904198593    0.00938138258417489\\
    2.41096285038311    0.00850781163737593\\
    2.5259566587803 0.00775081041470584\\
    2.64095046717749    0.00709052498321459\\
    2.75594427557467    0.00651115507750974\\
    2.87093808397186    0.006\\
    };
    \addplot [color=black, line width=1.0pt, forget plot]
      table[row sep=crcr]{%
    2.87093808397186    0.006\\
    4   0.006\\
    };
    \end{axis}
    \end{tikzpicture}

    \end{figure}



    \end{document}
4

Can't you just comment out the extra \addplots and make it one single plot?

Ie,

\documentclass[11pt]{scrartcl}
\usepackage[utf8x]{inputenc}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{lmodern}
\usepackage{mathtools}
\usepackage{amsfonts}
\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}


\begin{figure}

% This file was created by matlab2tikz.
%
\begin{tikzpicture}[%
line join = miter
]

\begin{axis}[%
width=0.856\textwidth,
height=0.54\textwidth,
at={(0\textwidth,0\textwidth)},
scale only axis,
xmin=0,
xmax=4,
xlabel style={font=\color{white!15!black}},
xlabel={Periodo $T\,[s]$},
ymin=0,
ymax=0.09,
ylabel style={font=\color{white!15!black}},
ylabel={$S_d\,[g]$},
axis background/.style={fill=white},
axis x line*=bottom,
axis y line*=left,
scaled y ticks = false,
y tick label style={/pgf/number format/.cd, fixed, fixed zerofill,precision=2, /tikz/.cd}
]
\addplot [color=black, line width=1.0pt, forget plot]
  table[row sep=crcr]{%
0   0.036\\
0.0109  0.0411876\\
0.0218  0.0463752\\
0.0327  0.0515628\\
0.0436  0.0567504\\
0.0545  0.061938\\
0.0654  0.0671256\\
0.0763  0.0723132\\
0.0872  0.0775008\\
0.0981  0.0826884\\
0.109   0.087876\\
%};
%\addplot [color=black, line width=1.0pt, forget plot]
 % table[row sep=crcr]{%
0.109   0.087876\\
0.327   0.087876\\
%};
% \addplot [color=black, line width=1.0pt, forget plot]
 % table[row sep=crcr]{%
0.327   0.087876\\
0.3967  0.0724362288883287\\
0.4664  0.0616111749571183\\
0.5361  0.0536009177392277\\
0.6058  0.0474338923737207\\
0.6755  0.0425395292376018\\
0.7452  0.0385607246376811\\
0.8149  0.0352625500061357\\
0.8846  0.0324841193759891\\
0.9543  0.0301115498270984\\
1.024   0.02806196484375\\
1.0937  0.0262736143366554\\
1.1634  0.0246995461578133\\
1.2331  0.0233034238910064\\
1.3028  0.0220566871354007\\
1.3725  0.0209365770491803\\
1.4422  0.0199247344335044\\
1.5119  0.0190061855942853\\
1.5816  0.0181685963581184\\
1.6513  0.0174017150124145\\
1.721   0.0166969506101104\\
%   };
%\addplot [color=black, line width=1.0pt, forget plot]
%  table[row sep=crcr]{%
1.721   0.0166969506101104\\
1.83599380839719    0.0146708906007282\\
1.95098761679437    0.0129924147965453\\
2.06598142519156    0.0115863349149064\\
2.18097523358874    0.0103967460331488\\
2.29596904198593    0.00938138258417489\\
2.41096285038311    0.00850781163737593\\
2.5259566587803 0.00775081041470584\\
2.64095046717749    0.00709052498321459\\
2.75594427557467    0.00651115507750974\\
2.87093808397186    0.006\\
%  };
%\addplot [color=black, line width=1.0pt, forget plot]
  %table[row sep=crcr]{%
2.87093808397186    0.006\\
4   0.006\\
};
\end{axis}
\end{tikzpicture}

\end{figure}



\end{document}

and here the result (I took a fragment there)

enter image description here

  • 1
    Thank you very much. Sometimes the answer is right before your nose! Ave! – Fungatt May 12 '17 at 16:19

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.