4

I have a CSV file with data which I want to plot, I can do this by using:

\begin{tikzpicture}
\begin{axis}
\addplot table [x=n, y=fn, col sep=comma, only marks] {dataratio.csv};
\end{axis}
\end{tikzpicture}

This does the job but my dots are colored blue, how do I make them black? Just adding color=black doesn't do anything for me.

Stefan Pinnow
  • 29,535
HolyMonk
  • 317

2 Answers2

6

This is most probably, because you are adding the options in the wrong place. Correct would be to use all non-table options in the options of \addplot, i.e. move only marks from the table options to the \addplot options.

This will already give you the desired result, but have a look at the comments in the code why this is so and what would be the right way to change the color to something else than black for \addplot or something else than the default cycle list color for \addplot+.

% used PGFPlots v1.14
    % just some dummy data to show the differences between the two methods
    \begin{filecontents*}{dataratio.csv}
        n,fn,fo
        0,0,1
        1,1,2
    \end{filecontents*}
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\begin{document}
    \begin{tikzpicture}
        \begin{axis}
            % because now an option is given to `\addplot` (and not `\addplot+` the default
            % cycle list doesn't apply any more and the color black is used.
            \addplot [
                only marks,
            ] table [x=n,y=fn,col sep=comma] {dataratio.csv};
            % *with* the `+' the default cycle list still is used and then you can change
            % the marker color with `mark options'
            \addplot+ [
                only marks,
                mark options={
%                    % will set both, the `draw' and the `fill' color
%                    black,
                    % or you can set them separately to whatever you like
                    draw=red,
                    fill=green,
                },
            ] table [x=n,y=fo,col sep=comma] {dataratio.csv};
        \end{axis}
    \end{tikzpicture}
\end{document}

image showing the result of above code

Stefan Pinnow
  • 29,535
-1

See, if

\begin{tikzpicture}
\begin{axis}
\addplot[only marks, mark color=black] table [x=n, y=fn, col sep=comma] {dataratio.csv};
\end{axis}
\end{tikzpicture}

gives desired rezultat.

Zarko
  • 296,517
  • Works, thanks! :) I did color instead of mark color – HolyMonk Jan 03 '17 at 19:06
  • 2
    That solutions works, but not because of mark color=black, which only changes the "other" color for the markers halfcircle, halfcircle*, halfdiamond* and halfsquare*. Please have a look at my solution to find out, why yours is working unintended. – Stefan Pinnow Jan 03 '17 at 19:21