11

Instead of the samples which were marked via mark=-, I would like to have horizontal lines that fill the entire axis from left to right. Had the idea to tune the dashes via mark size=6cm but I did not find out how to clip them at the plot's borders.

Picture

enter image description here

MWE

\documentclass[a4paper
]{scrartcl}

\usepackage{
tikz,
pgfplots,
amsmath
}

\usepackage[T1]{fontenc}
\usepackage{
lmodern,
textcomp,
siunitx
}

\begin{document}
\begin{center}
\begin{tikzpicture}[font=\small]
\begin{axis}[
height=5cm,
width=6cm,
scale only axis=true,
%
xlabel={\(\alpha\) in \si{\degree}},
ylabel={\(\sin{(\alpha)}\)},
%
xtick=\empty, ytick=\empty, xticklabels={,,}, yticklabels={,,}, xmajorgrids={false}, ymajorgrids={false}
]
\addplot+[domain=0:360, samples=25, only marks, mark=-] {sin(x)};
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}
  • You mean xcomb? – percusse Apr 27 '14 at 14:43
  • I think it might work, but how would I get them to the right edge? – henry Apr 27 '14 at 14:48
  • You could abuse grid lines: use ytick=data and activate grid lines for y. Would that be acceptable or do you ever need y tick labels? – Christian Feuersänger Apr 27 '14 at 14:56
  • @ChristianFeuersänger Yes, I do. It's just one of four pictures in a group plot for a little showcase of quantization. – henry Apr 27 '14 at 15:04
  • @percusse I think it might work, but how would I get them to the right edge? – henry Apr 27 '14 at 15:05
7

enter image description here

\documentclass[a4paper]{scrartcl}

\usepackage{
tikz,
pgfplots,
amsmath
}

\usepackage[T1]{fontenc}
\usepackage{
lmodern,
textcomp,
siunitx
}

\begin{document}
\begin{center}
\begin{tikzpicture}[font=\small]
\begin{axis}[
height=5cm,
width=6cm,
scale only axis=true,
%
xlabel={\(\alpha\) in \si{\degree}},
ylabel={\(\sin{(\alpha)}\)},
%
xtick=\empty, ytick=\empty, xticklabels={,,}, yticklabels={,,}, xmajorgrids={false}, ymajorgrids={false},
after end axis/.code={
\foreach \i in {90,105,...,270} {% to avoid duplicated lines
\pgfmathparse{sin(\i)} ;
\draw(axis cs:\pgfkeysvalueof{/pgfplots/xmin},\pgfmathresult)--(axis cs:\pgfkeysvalueof{/pgfplots/xmax},\pgfmathresult) ;} ;
}
}
]
\addplot+[domain=0:360, samples=25, only marks, mark=-] {sin(x)};
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}
|improve this answer|||||

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.