3

In my code below, there is a marker in the legend. I just have two plots without any markers. How to remove these markers and just have the line be shown in the legend entry?

Here is my code:

\documentclass{book}
\usepackage{tikz}
\usepackage{pgfplots}
\clearpage
\pgfplotsset{minor grid style={dotted,gray!50}}
\pgfplotsset{major grid style={gray!50!black}}

\begin{filecontents*}{Noise.dat}
  Freq   Orig   Filt
100.000, -79.374, -119.392
101.801, -79.858, -119.321
103.634, -78.587, -117.497
1000, -79.077, -117.437
1070.401, -78.735, -116.547
1090.335, -81.799, -119.065
11100.304, -82.298, -119.021
11300.309, -82.329, -118.511
115000.349, -81.744, -117.389
\end{filecontents*}


\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[every plot/.append style={very thick}]
\begin{semilogxaxis}[width=14cm,height=10cm,
                    grid = both,
                    every major grid/.style={gray, opacity=0.7},
                    title = {},
                    xlabel={\emph{Offset Frequency (Hz)}},
                    ylabel={\emph{Phase Noise (dBc/Hz)}}]

\addplot table[mark = none, x index=0,y index=1,col sep=comma] {Noise.dat};
\addlegendentry{\emph{Original Phase Noise Data}}

\addplot table[mark = none, x index=0,y index=2,col sep=comma] {Noise.dat};
\addlegendentry{\emph{Filtered Noise Data}}
\end{semilogxaxis}
\end{tikzpicture}
\caption[Original and Filtered Response.]{Original and Filtered Response.}
\end{figure}
\end{document} 

1 Answer 1

3

The problem is that you have added mark=none as an option to table, not to \addplot. You should have written \addplot+ [mark=none] table .... The + indicates that the style of the line will not be completely overwritten by [mark=none], so the color cycle is continued. Without the + you would get a black line.

To make all plots very thick you can add every axis plot/.append style={very thick} to the axis options, and by adding no markers to the axis options there will be no markers in all the plots.

By the way, you can add multiple things in one \pgfplotsset, just separate by comma. You also had a stray \clearpage in the preamble, and the whole plot was wider than \textwidth, causing it to protrude into the right margin.

enter image description here

\documentclass{book}
\usepackage{pgfplots}
\pgfplotsset{
  minor grid style={dotted,gray!50},
  major grid style={gray!50!black}
}

\begin{filecontents*}{Noise.dat}
  Freq   Orig   Filt
100.000, -79.374, -119.392
101.801, -79.858, -119.321
103.634, -78.587, -117.497
1000, -79.077, -117.437
1070.401, -78.735, -116.547
1090.335, -81.799, -119.065
11100.304, -82.298, -119.021
11300.309, -82.329, -118.511
115000.349, -81.744, -117.389
\end{filecontents*}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{semilogxaxis}[width=\textwidth,height=10cm,
                    grid = both,
                    every major grid/.style={gray, opacity=0.7},
                    title = {},
                    xlabel={\emph{Offset Frequency (Hz)}},
                    ylabel={\emph{Phase Noise (dBc/Hz)}},
                    no markers,
                    every axis plot/.append style={very thick}]

\addplot table[x index=0,y index=1,col sep=comma] {Noise.dat};
\addlegendentry{\emph{Original Phase Noise Data}}

\addplot table[x index=0,y index=2,col sep=comma] {Noise.dat};
\addlegendentry{\emph{Filtered Noise Data}}
\end{semilogxaxis}
\end{tikzpicture}
\caption[Original and Filtered Response.]{Original and Filtered Response.}
\end{figure}
\end{document} 
4
  • T. Thanks for your response. It worked. Is it also possible to increase the thickness of the legend lines to match the plot lines?
    – Joe
    Dec 16, 2015 at 21:34
  • @Joe The very thick part is a bit wrong at the moment, will fix soon. Dec 16, 2015 at 21:42
  • @ Torbjorn T., Thanks for your solutions. The only issue that I have is that with the new placement of the very thick command, this also makes the borders of both the legend and plot also very thick. Is it possible to "localize" the very thick command to just the legend entries? Thanks again.
    – Joe
    Dec 16, 2015 at 21:51
  • @Joe That was the reason for my previous comment, and the answer is updated to address that. Dec 16, 2015 at 21:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .