1

for whatever reason in this pgfplot the vertical grid lines are overlapping the axis (which looks ugly) even though I use a pretty similar axis for another plot where the grid lines don't overlap. This is how it looks like:

enter image description here

Minimal working example:

\documentclass[a4paper,12pt]{report}

\usepackage{float}
\usepackage{tikz}
\usepackage{pgf}
\usepackage{pgfplots, pgfplotstable}

\begin{document}

\begin{figure}[H]
  \centering
    \begin{tikzpicture}
        \pgfplotsset{every tick label/.append style={font=\tiny}}
        \pgfplotstableread[col sep=comma]{socket_ltncy_30s_recvmsg_8x1080p50_24g.csv}\datatable
        \centering
        \begin{axis}[
            ybar,
            ylabel near ticks,
            axis line style = thin,
            grid=major, grid style={gray!30},
            bar width=.01cm,
            width=\textwidth,
            height=3cm,
            xmin = 0,
            xmax = 150,
            ymin = 0,
            ymax = 100,
            xtick distance = {25},
            ytick distance = {25},
            yticklabel={\pgfmathprintnumber\tick\%},
            xlabel={Latency in $\mu$s},
            ylabel={ \textcolor{black}{Percent} },
            label style={font=\scriptsize},
            bar shift=0mm
            ],
            \addplot[
              draw=black,
              fill=black,
              bar shift=0mm
            ] table [
                x={LATENCY},
                y={PERCENT},
                restrict expr to domain={y}{0.1:100}
              ]{\datatable};

            \addplot[
              scatter,
              only marks,
              mark=x,
              color=black,
              scatter/use mapped color={draw=black}
            ] table [
                x={LATENCY},
                y={PERCENT},
                restrict expr to domain={y}{0.000001:0.1}
            ]{\datatable};

            \addplot[
              draw=green,
              fill=green,
              bar shift=0mm
            ] table [
                x={LATENCY},
                y={PERCENT},
                restrict expr to domain={\thisrow{IS_MEDIAN}}{1:1}
              ]{\datatable};

            \addplot[
              draw=red,
              fill=red,
              bar shift=0mm
            ] table [
                x={LATENCY},
                y={PERCENT},
                restrict expr to domain={\thisrow{IS_MEAN}}{1:1}
              ]{\datatable};
        \end{axis}
      \end{tikzpicture}
\end{figure}

\end{document}

with data socket_ltncy_30s_recvmsg_8x1080p50_24g.csv looking something like this

LATENCY,PERCENT,IS_MEDIAN,IS_MEAN
2,8.04666667,0,0
3,9.87416667,1,1
4,23.75833333,0,0
5,0.65000000,0,0
6,0.54166667,0,0
7,0.62416667,0,0
8,0.59750000,0,0
9,0.14500000,0,0
10,0.05166667,0,0
11,0.05583333,0,0
12,0.05166667,0,0
13,0.05333333,0,0
14,0.05666667,0,0
15,0.04833333,0,0
16,0.05583333,0,0
17,0.06166667,0,0
18,0.06083333,0,0
19,0.05666667,0,0
20,0.05833333,0,0

I want them to "bend" inwards, like this:

enter image description here

Thank you!

1 Answer 1

1

It's not the gridlines, but the ticks. Add tick align=inside to the axis options, after the ybar options. (ybar seems to set xtick align=outside, so you need to overwrite that setting.)

Irrelevant sidenotes: pgfplots loads tikz and therefore also pgf, so you don't need to explicitly load the latter two when you have pgfplots. And the \centering that is inside the tikzpicture environment doesn't actually do anything, I think, so you can remove that.

Minimal example:

\documentclass{report}
\usepackage{pgfplots}
\begin{document}
    \begin{tikzpicture}
        \begin{axis}[
            ybar,
            %tick align=inside % uncomment this to see difference
            ]
            \addplot {rnd};
        \end{axis}
      \end{tikzpicture}
\end{document}
1
  • Thank you so much! May 21, 2020 at 14:31

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.