0

I'm trying to plot colored histogram in subfigure environment. But when setting chart dimensions to \linewidth I got what follows, which is definitely not what I expect.

enter image description here

    \begin{subfigure}[t]{.48\linewidth}
    \begin{tikzpicture}
      \begin{axis}[
        width=\linewidth,
        height=.5\linewidth,
        yticklabels={},
      ]
        \addplot coordinates {(0,117)};
        \addplot coordinates {(1,1041)};
        \addplot coordinates {(10,2162)};
        \addplot coordinates {(11,776)};
      \end{axis}
    \end{tikzpicture}
    \caption{Histogram of $I_{sc}$}
  \end{subfigure}

How can I force pgfplots to occupy all the given space/remove padding/margins/or whatever it is?

If scale only axis used as suggested, margin is still present and chart lands into next subplot.

enter image description here

Partial solution is to set ytick=\empty solves placement problem, but removes ticks entirely...

majkrzak
  • 143
  • 1
    When you set width=X, height=Y, the dimensions of the axis box itself becomes (X-45pt) by (Y-45pt), where 45pt is a hardcoded length pgfplots adds to give space for labels. If you add scale only axis, the dimensions of become X by Y. If adding scale only axis isn't enough, you could try https://tex.stackexchange.com/questions/561201/pgfplots-figure-with-fixed-width/561238#561238 though. – Torbjørn T. Nov 10 '20 at 20:46
  • Is there a way to drop those margins? Scale only axis will result in overflow – majkrzak Nov 10 '20 at 21:31
  • Which margins exactly? Sorry though, I don't have any really good options. A perhaps pragmatic, albeit manual, option is to do e.g. scale only axis, width=0.98\linewidth,... – Torbjørn T. Nov 10 '20 at 21:43
  • ehrn scale only axes is on, bottom left corner of chart is in same place and right side gets out of subchart part – majkrzak Nov 10 '20 at 21:45
  • adding \clip (0,0) rectangle (\linewidth, \linewidth); hellped in ugly manner – majkrzak Nov 10 '20 at 21:46
  • Yes, I saw that it pokes out the right side a bit, but I didn't get what you meant by "drop those margins". Drop what, where? I'd reduce the width rather than clipping, I think. – Torbjørn T. Nov 10 '20 at 21:50
  • applying ticks=none helps a bit. chart is place, but no ticks present :D – majkrzak Nov 10 '20 at 21:53

0 Answers0