我想根据顶点绘制一个正方形。例如:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\usepgfplotslibrary{fillbetween}
\begin{document}
\begin{center}
\begin{tikzpicture}[scale=1]
\begin{axis}[xmin=0,xmax=1,ymin=0,ymax=1,enlargelimits=false,xlabel=$a_1$,ylabel=$a_2$]
\addplot [blue!80!black,fill=blue,fill opacity=0.4]
coordinates
{(0, 0) (0, 0.436694) (0.436694, 0) (0.436694, 0.436694)}
|- (axis cs:0,0) -- cycle;
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}
但此代码绘制:
我想绘制正方形而不必删除点(0.436694, 0)
。
问候
答案1
在这个例子中(或此类例子中),你当然可以作弊。你需要做的就是添加ybar interval
。
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepgfplotslibrary{fillbetween}
\begin{document}
\begin{center}
\begin{tikzpicture}[scale=1]
\begin{axis}[xmin=0,xmax=1,ymin=0,ymax=1,enlargelimits=false,xlabel=$a_1$,ylabel=$a_2$]
\addplot [blue!80!black,fill=blue,fill opacity=0.4,ybar interval]
coordinates
{(0, 0) (0, 0.436694) (0.436694, 0) (0.436694, 0.436694)}
|- (axis cs:0,0) -- cycle;
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}