8

everyone:

I want to use tikz to draw a figure like this one:

enter image description here

But I don't know how to add help line and background color So I just get this figure: enter image description here

How can I change my code? anyone can help me?

\documentclass{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}

\begin{document}

\begin{figure}
    \centering
    \begin{tikzpicture}
    \begin{axis}[
        xtick={0,40,...,160},
        ymin=0,
        ymax=12,
        xmin=0,
        xmax=180,
        grid style=dashed,
        yticklabel style = {font=\tiny},
        xticklabel style = {font=\tiny},
        legend style={draw=none,font=\tiny,legend pos=south east,cells={anchor=west}}
    ]

        \addplot[
        color=blue,
        mark=square,
        ]
        coordinates {
        (40,8.35)
        (60,7.87)
        (80,7.51)
        (100,7.32)
        (120,7.15)
        (140,7.02)
        (160,6.97)
        };
        \addlegendentry{S$_1+$ S$_2$= 200}

        \addplot[
        color=red,
        mark=square,
        ]
        coordinates {
        (40,9.54)
        (60,9.35)
        (80,8.77)
        (100,8.81)
        (120,8.66)
        (140,8.29)
        (160,8.59)
        };
        \addlegendentry{S$_1+$ S$_2$= 300}

    \end{axis}
    \end{tikzpicture}
  \caption{Comparison of S}
  \label{step_decay_test_performance}
\end{figure}

\end{document}
8

You've set the grid style, but you haven't actually activated the grid. Add grid to the axis options. To set the background colour, axis background/.style={fill=blue!10}. If you want the legend to have the same colour, add the same fill to the legend style.

enter image description here

\documentclass{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}

\begin{document}

\begin{figure}
    \centering
    \begin{tikzpicture}
    \begin{axis}[
        xtick={0,40,...,160},
        ymin=0,
        ymax=12,
        xmin=0,
        xmax=180,
        grid, % <---- added
        grid style=dashed,
        yticklabel style = {font=\tiny},
        xticklabel style = {font=\tiny},
        legend style={draw=none,font=\tiny,legend pos=south east,cells={anchor=west}},
        axis background/.style={fill=blue!10} % <--- added
    ]

        \addplot[
        color=blue,
        mark=square,
        ]
        coordinates {
        (40,8.35)
        (60,7.87)
        (80,7.51)
        (100,7.32)
        (120,7.15)
        (140,7.02)
        (160,6.97)
        };
        \addlegendentry{S$_1+$ S$_2$= 200}

        \addplot[
        color=red,
        mark=square,
        ]
        coordinates {
        (40,9.54)
        (60,9.35)
        (80,8.77)
        (100,8.81)
        (120,8.66)
        (140,8.29)
        (160,8.59)
        };
        \addlegendentry{S$_1+$ S$_2$= 300}

    \end{axis}
    \end{tikzpicture}
  \caption{Comparison of S}
  \label{step_decay_test_performance}
\end{figure}

\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.