凡例の四角いマークを塗りつぶしますか?

凡例の四角いマークを塗りつぶしますか?

私は次のコードを使用して簡単なグラフを生成しています。凡例に、グラフの網掛け部分を表す灰色の塗りつぶされた四角形を表示したいと考えています。それでも、すべてが白い四角形のマークにつながります。

    \begin{tikzpicture}
\begin{axis}[
    inner axis line style={>={Latex[round]}},
    axis lines=left,
    ymin=0,
    ymax=10,
    xmin=0,
    xmax=10,
    yticklabels={,,},
    xticklabels={,,},
    ticks=none,
    xlabel=Quantity (q),
    ylabel=Price (\$),
    legend entries={
        total willingness to pay,
        marginal willingness to pay
    },
    legend pos=north east,
    legend style={draw=none}
    ]
    \addlegendimage{only marks, mark=square}
    \addlegendimage{only marks, mark=o}
    \addplot[solid,domain=0:10,samples=100]{-5/2*x^(1/2)+15/2};
    \addplot[draw=none,name path=A,domain=3:6,fill=gray]{-5/2*x^(1/2)+15/2}\closedcycle;    
\end{axis}
\end{tikzpicture}

助けてくれてありがとう!

答え1

塗りつぶすには、 のmark=square*代わりにを使用する必要があります。 を使用すると、選択した色で塗りつぶすことができます。mark=squarecolor

\documentclass[border=1mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    inner axis line style={>={Latex[round]}},
    axis lines=left,
    ymin=0,
    ymax=10,
    xmin=0,
    xmax=10,
    yticklabels={,,},
    xticklabels={,,},
    ticks=none,
    xlabel=Quantity (q),
    ylabel=Price (\$),
    legend entries={
        total willingness to pay,
        marginal willingness to pay
    },
    legend pos=north east,
    legend style={draw=none}
    ]
    \addlegendimage{only marks, mark=square*,color=gray}
    \addlegendimage{only marks, mark=o}
    \addplot[solid,domain=0:10,samples=100]{-5/2*x^(1/2)+15/2};
    \addplot[draw=none,domain=3:6,fill=gray]{-5/2*x^(1/2)+15/2}\closedcycle;
\end{axis}
\end{tikzpicture}
\end{document}

上記コードの結果を示す画像

関連情報