0

enter image description hereMy xticks overlap because they are not evenly spaced. Initial xticks are 2 to 5 points apart whereas, later ones are 50 points apart.

I want to plot at following points 1,2,5,10,20,50,150,200,250 and 300.

Below is my code

\documentclass[journal]{IEEEtran}
\usepackage{graphicx}
\usepackage{epstopdf}
\usepackage{tikz}
\usepackage{etoolbox}
\usepackage{pgfplots}
\usepackage[font=small,labelfont=bf]{caption}

\begin{document}
    \pgfplotsset{footnotesize,samples=10}
    \begin{figure}
    \centering
    \begin{tikzpicture}
    \begin{axis}[ % The height and width argument only apply to the actual axis
    height=5cm,
    width=12cm,
    xlabel={Packets Generation Rate (Packets/s)},
    ylabel={Throughput (kbps)},
    xmin=0, xmax=300,
    ymin=0, ymax=8,
    xtick= {1,2,5,10,20,50,100,150,200,250,300},
 %   xticklabels = {1,2,5,10,20,50,100,150,200,250,300},
    ytick= {0,1,2,3,4,5,6,7,8},
    legend pos=outer north east,
    ymajorgrids=true,
    grid style=dashed,
    ]
    \addplot+[
    color=blue,
    thick,
    smooth,
    ]
    coordinates {
    (1  ,1.7)(2 ,2.7)(5 ,4)(10  ,5.5)(20    ,5.2)(50    ,6.2)(100,  7)(150, 6.5)(200,   5.9)(250,   5.2)(300,   4.8)};
    \label{plot_two}
    \addlegendentry{1-hop}
    \addplot+[
    color=magenta,
    thick,
    smooth,
    ]
    coordinates {
    (1      ,1.5)(2     ,2.3)(5     ,3.1)(10    ,   3.9)(20 ,   4)(50   ,   4.8)(100,       5)(150,     4.1)(200,       3.8)(250,       3.8)(300,       2.5)};
    \addlegendentry{2-hop}

    \addplot+[
    color=black,
    thick,
    smooth,
    ]
    coordinates {
    (1      ,   1.5)(2      ,   2)(5        ,   2.5)(10 ,       3)(20   ,       2.8)(50 ,       3.6)(100,           3.6)(150,           3.2)(200,           2.9)(250,           2.4)(300,           1.8)};
    \addlegendentry{3-hop}
    \addplot+[
    color=orange,
    thick,
    smooth,
    ]
    coordinates {
    (1      ,1.4)(2     ,1.9)(5     ,2.1)(10    ,   2.7)(20 ,   2.4)(50 ,   2.8)(100,       2.7)(150,       2.3)(200,       1.9)(250,       1.8)(300,       1.7)};
    \addlegendentry{4-hop}
    \addplot+[
    color=green,
    thick,
    smooth,
    ]
    coordinates {
    (1      ,1.2)(2     ,1.6)(5     ,1.9)(10    ,   2.1)(20 ,   2.2)(50 ,   2.5)(100,       2.3)(150,       2)(200,     1.7)(250,       1.3)(300,       1.1)};
    \addlegendentry{5-hop}
    \end{axis}
    \end{tikzpicture}
    \end{figure}

\end{document}
  • Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – Stefan Pinnow Mar 27 '18 at 9:35
  • 1
    So do you want to use a parametric plot, so that 1,2,5,10 are evenly spaced? Do you want to make some of them minor ticks (no label)? – John Kormylo Mar 27 '18 at 14:06
1

A quick answer could be to use two axis environments, with different options to select the plot range of each one. Then use a scope to obtain a shared centered xlabel for both axis.

enter image description here

I a pretty sure there are prettier solutions, especially regarding the relative positionning of the two axis using some bounding boxes.

\documentclass{article}
\usepackage{graphicx}
\usepackage{epstopdf}
\usepackage{tikz}
\usepackage{etoolbox}
\usepackage{pgfplots}
\usepackage[font=small,labelfont=bf]{caption}
\pgfplotsset{footnotesize,samples=10,compat=1.5}
\usetikzlibrary{positioning,calc}

\newcommand{\axistoberepeated}[2]{

\begin{axis}[ % The height and width argument only apply to the actual axis
height=5cm,
width=5cm,
ylabel={Throughput (kbps)},
xmin=0, xmax=20,
ymin=0, ymax=8,
xtick= {1,2,5,10,20,50,100,150,200,250,300},
%   xticklabels = {1,2,5,10,20,50,100,150,200,250,300},
ytick= {0,1,2,3,4,5,6,7,8},
legend pos=outer north east,
ymajorgrids=true,
grid style=dashed,
#1
]
\addplot+[
color=blue,
thick,
smooth,
]
coordinates {
(1  ,1.7)(2 ,2.7)(5 ,4)(10  ,5.5)(20    ,5.2)(50    ,6.2)(100,  7)(150, 6.5)(200,   5.9)(250,   5.2)(300,   4.8)};
\label{plot_two}
\addlegendentry{1-hop}
\addplot+[
color=magenta,
thick,
smooth,
]
coordinates {
(1      ,1.5)(2     ,2.3)(5     ,3.1)(10    ,   3.9)(20 ,   4)(50   ,   4.8)(100,       5)(150,     4.1)(200,       3.8)(250,       3.8)(300,       2.5)};
\addlegendentry{2-hop}

\addplot+[
color=black,
thick,
smooth,
]
coordinates {
(1      ,   1.5)(2      ,   2)(5        ,   2.5)(10 ,       3)(20   ,       2.8)(50 ,       3.6)(100,           3.6)(150,           3.2)(200,           2.9)(250,           2.4)(300,           1.8)};
\addlegendentry{3-hop}
\addplot+[
color=orange,
thick,
smooth,
]
coordinates {
(1      ,1.4)(2     ,1.9)(5     ,2.1)(10    ,   2.7)(20 ,   2.4)(50 ,   2.8)(100,       2.7)(150,       2.3)(200,       1.9)(250,       1.8)(300,       1.7)};
\addlegendentry{4-hop}
\addplot+[
color=green,
thick,
smooth,
]
coordinates {
(1      ,1.2)(2     ,1.6)(5     ,1.9)(10    ,   2.1)(20 ,   2.2)(50 ,   2.5)(100,       2.3)(150,       2)(200,     1.7)(250,       1.3)(300,       1.1)};
\addlegendentry{5-hop}
#2
\end{axis}


}

\begin{document}

    \begin{figure}
    \centering
    \begin{tikzpicture}
      \begin{scope}
        \axistoberepeated{
        anchor = south west,
        local bounding box=axe1,
        xmin=0,xmax=20,width=4.5cm,
        }{\legend{}}

        \axistoberepeated{
        anchor = south west,
        local bounding box=axe2,
        xmin=20,xmax=300,xshift=4cm,width=9cm,
        yticklabels=\empty,ylabel=\empty
        }{}
    \end{scope}
    \node[label={[yshift=-1cm]Packets Generation Rate (Packets/s)}] at (current bounding box.south) {};
    \end{tikzpicture}
    \end{figure}

\end{document}
| improve this answer | |

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.