Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
    
You mean xcomb? –  percusse Apr 27 at 14:43
    
I think it might work, but how would I get them to the right edge? –  henry Apr 27 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 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 at 15:04
    
@percusse I think it might work, but how would I get them to the right edge? –  henry Apr 27 at 15:05
add comment

1 Answer 1

up vote 7 down vote accepted

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}
share|improve this answer
1  
To avoid that 4pt offset, you can use \draw(axis cs:\pgfkeysvalueof{/pgfplots/xmin},\pgfmathresult)--(axis cs:\pgfkeysvalueof{/pgfplots/xmax},\pgfmathresult) ; –  Torbjørn T. Apr 27 at 14:58
    
Done, thanks for the tip I didn't knew. –  Tarass Apr 27 at 15:01
2  
Unsurprisingly, I got it from this site myself. tex.stackexchange.com/questions/22018 tex.stackexchange.com/questions/124199 –  Torbjørn T. Apr 27 at 15:05
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.