
Я использую следующий код для генерации простого графика и хочу, чтобы легенда отображала закрашенный серый квадрат, представляющий затененную область на графике. Все по-прежнему приводит к белой квадратной отметке.
\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=square
для заполнения. С помощью color
вы можете затем заполнить его цветом по вашему выбору.
\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}