1

How can I align the left side of the bars with the x-value they're "assigned" to?

In my bar chart the first bar overlaps the y axis but I want it to be to the right of the y axis.

enter image description here

So for all bars, rather than their centres aligning with the corresponding x-values their left edges are aligned.

How do I do that?

\begin{tikzpicture}
    \begin{axis}[
        axis lines = center,
        axis line style = {-},
        xlabel = $$,
        ylabel = $$,
        xmin = 0,
        xmax = 0.001,
        clip=false,
        xtick = {0, 0.001},
        xticklabels = {,},
        ymin = -1,
        ymax = 1,
        ytick = {-1,0,1},
        height = 10em,
        width = 30em,
      ]
      \addplot [
        ybar,
        fill=blue,
        bar width=0.000005,
        draw=none,
      ]
      coordinates {
        (0,0.00928)
        (0.00002083333,0.23672)
        (0.00004166667,0.31467)
        (0.0000625,0.58179)
        (0.00008333333,0.46774)
        (0.0001041667,0.71017)
        (0.000125,0.45074)
    };
  \end{axis}
\end{tikzpicture}

1 Answer 1

1

By default you get the bars centered on the x-coordinate, but that can be modified with the bar shift parameter. You just need to set bar shift=0.0000025, i.e. half the bar width.

part of code output

\documentclass[12pt]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        axis lines = center,
        axis line style = {-},
        xlabel = $$,
        ylabel = $$,
        xmin = 0,
        xmax = 0.0002,
        clip=false,
        xtick = {0, 0.001},
        xticklabels = {,},
        ymin = -1,
        ymax = 1,
        ytick = {-1,0,1},
        height = 10em,
        width = 30em,
        ybar,
      ]
      \addplot [
        fill=blue,
        bar width=0.000005,
        bar shift=0.0000025,
        draw=none,
      ]
      coordinates {
        (0,0.00928)
        (0.00002083333,0.23672)
        (0.00004166667,0.31467)
        (0.0000625,0.58179)
        (0.00008333333,0.46774)
        (0.0001041667,0.71017)
        (0.000125,0.45074)
    };
  \end{axis}
\end{tikzpicture}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .