# Set real dimensions of pgfplot

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.

\begin{subfigure}[t]{.48\linewidth}
\begin{tikzpicture}
\begin{axis}[
width=\linewidth,
height=.5\linewidth,
yticklabels={},
]
\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.

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

• 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 tex.stackexchange.com/questions/561201/… though. Nov 10 '20 at 20:46
• Is there a way to drop those margins? Scale only axis will result in overflow 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,... 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 Nov 10 '20 at 21:45
• adding \clip (0,0) rectangle (\linewidth, \linewidth); hellped in ugly manner Nov 10 '20 at 21:46