I need to have my x-labels in my pgfplots to be vector graphics. How can I prevent the graphical x-labels from streching?
In below is a MWE that can duplicate my problem. The drawn rectangles and circles are stretched and distorted below the x-axis (the circles became ellipses).
I am looking for a way such that the aspect ratio of graphical labels become insensitive to the size of the axis similar to the way numbers are printed as axis labels, i.e., xticklabels={0, 90, 180, 270, 360}. No matter what the size of the axis is, the result will come out very nice with the correct and proper aspect ratio if the xticklabels are just numbers. I want to be able to have the same thing when I am using graphics as xticklabels instead of plain numbers/texts.
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\usepackage{tkz-euclide}
\usetikzlibrary{patterns}
\begin{filecontents*}{data.csv}
a,b,c
0,4,1
90,3,2
180,5,3
270,1,4
360,3,5
\end{filecontents*}
\newcommand{\mL}{5}
\newcommand{\mW}{30}
\pgfplotsset{compat=newest,height = 10cm, width = 20cm}
\pgfplotsset{minor grid style={dotted}}
\newcommand{\myGfxLabels}[1]
{
\begin{tikzpicture}
\tkzDefPoint( {\mL},-{\mW}){B};
\foreach \xDelta in {0}
{
\draw[->,line width=1pt,rotate={0},red] ({\mL+\xDelta}, -{1.5*\mW}) -- ({\mL+\xDelta},-{\mW});
}
\draw[fill=red!50!yellow,pattern=north east lines,shift={(0 cm,0 cm)},rotate around={-#1:(B)},xscale=1,yscale=1,] ({\mL}, {\mW}) -- ({\mL},-{\mW}) -- (-{\mL},-{\mW}) -- (-{\mL},{\mW}) -- ({\mL}, {\mW});
\draw[] (B) circle ({\mL});
\end{tikzpicture}
}
\begin{document}
\begin{tikzpicture}
\begin{axis}
[
xlabel={$\phi$},
ylabel={$dL_{\rm cavity}$},
xtick={0, 90, 180, 270, 360},
xticklabels={\myGfxLabels{0}, \myGfxLabels{90}, \myGfxLabels{180}, \myGfxLabels{270}, \myGfxLabels{360}},
smooth,
grid=both,
minor tick num=2,
title={Title},
]
\addplot+ table [x=a, y=b,col sep=comma] {data.csv};
\end{axis}
\end{tikzpicture}
\end{document}


tikzpictures often leads to problems. A workaround is to use thestandaloneclass to create a PDF containing the images, and then use\includegraphicsin the ticklabels. (I only get aDimension too largeerror from your code, by the way.) – Torbjørn T. Jun 16 '16 at 05:47disabledatascalingto theaxisoptions. (If I do that the code compiles, but I don't get any ticklabels at all.) – Torbjørn T. Jun 16 '16 at 06:09disabledatascalingdidn't help. There should be a way around this problem, looks solvable! I also checked some of the solutions here: http://tex.stackexchange.com/questions/4338/correctly-scaling-a-tikzpicture. No success so far. I was hopeful that\resizeboxcan fix the issue, but I was wrong. I don't know, maybe I am not using them correctly. – shashashamti2008 Jun 16 '16 at 06:27[x=1pt,y=1pt]to thetikzpicturefor the x-tick label picture inside\myGfxLabelsachieve the desired result? – Mark Wibrow Jun 16 '16 at 10:11