我想用 TikZ 画这幅图。我用了下面的代码。但结果并不好(图 1)。而图 2 是正确的形式。
不知道问题出在哪里? 我的texlive版本是2012。
请在这方面指导我。
\begin{tikzpicture}
\begin{axis}[area legend,
axis x line=bottom,
axis y line=left,
domain=0:1,
legend style={at={(0.03,0.97)},
anchor=north west},
axis on top,xmin=0]
\addplot[pattern=crosshatch dots,
pattern color=blue,draw=blue,
samples=500]
{sqrt(x)} \closedcycle;
\addplot[pattern=crosshatch,
pattern color=blue!30!white,
draw=blue!30!white]
{x^2} \closedcycle;
\addplot[red,line legend] coordinates {(0,0) (1,1)};
\legend{$\sqrt x$,$x^2$,$x$}
\end{axis}
\end{tikzpicture}
答案1
\documentclass[pstricks,border=0pt,12pt,dvipsnames]{standalone}
\usepackage{amsmath}
\usepackage{pst-plot}
\usepackage{pst-math}
\usepackage[nomessages]{fp}
\FPeval\XMin{0-0}
\FPeval\XMax{6}
\FPeval\YMin{0-0}
\FPeval\YMax{36}
\FPeval\XOL{0} % of DeltaX
\FPeval\XOR{1/3} % of DeltaX
\FPeval\YOB{0} % of DeltaY
\FPeval\YOT{1/3} % of DeltaY
\FPeval\DeltaX{1}
\FPeval\DeltaY{5}
\FPeval\AxisL{XMin+DeltaX*XOL}
\FPeval\AxisR{XMax+DeltaX*XOR}
\FPeval\AxisB{YMin+DeltaY*YOB}
\FPeval\AxisT{YMax+DeltaY*YOT}
\newlength\Width\Width=8cm
\newlength\Height\Height=12cm
\newlength\llx\llx=-25pt
\newlength\urx\urx=15pt
\newlength\lly\lly=-25pt
\newlength\ury\ury=15pt
\newpsstyle{mygrid}
{
Dx=\DeltaX,
Dy=\DeltaY,
labels=none,
subticks=5,
tickwidth=.4pt,
subtickwidth=.2pt,
tickcolor=Orange!20,
subtickcolor=ForestGreen!20,
xticksize=\YMin\space \YMax,
yticksize=\XMin\space \XMax,
subticksize=1,
}
\psset
{
llx=\llx,
lly=\lly,
urx=\urx,
ury=\ury,
labelFontSize=\scriptstyle,
xAxisLabel=$x$,
yAxisLabel=$y$,
algebraic,
plotpoints=200,
}
\def\f{x^2}
\def\g{x}
\def\h{sqrt(x)}
\begin{document}
\pslegend[rt]{%
\color{Red}\rule{12pt}{1pt} & \color{Red} $y=x^2$\\
\color{Green}\rule{12pt}{1pt} & \color{Green} $y=x$ \\
\color{Blue}\rule{12pt}{1pt} & \color{Blue} $y=\sqrt x$
}
\begin{psgraph}
[
Dx=\DeltaX,
Dy=\DeltaY,
linecolor=lightgray,
tickcolor=gray,
ticksize=-3pt 3pt,
axespos=top,
]{->}(0,0)(\AxisL,\AxisB)(\AxisR,\AxisT){\dimexpr\Width-\urx+\llx}{\dimexpr\Height-\ury+\lly}
\psaxes[style=mygrid](0,0)(\XMin,\YMin)(\XMax,\YMax)
\psplot[linecolor=Red]{0}{\XMax}{\f}
\psplot[linecolor=Green]{0}{\XMax}{\g}
\psplot[linecolor=Blue]{0}{\XMax}{\h}
\end{psgraph}
\end{document}