我想用蓝色填充这个区域,有人可以帮帮我吗?(我是初学者)
多谢
\usepackage{tikz}
\usetikzlibrary{decorations,arrows, intersections, through}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{calc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{mathrsfs}
\usetikzlibrary{arrows}
\usetikzlibrary{quotes,angles}
\begin{tikzpicture}
\begin{axis} [xtick distance=1,legend pos=outer north east,xmin=-3,xmax=3,ymin=-8,ymax=8]
\addplot +[no markers,
raw gnuplot,
very thick,
empty line = jump % not strictly necessary, as this is the default behaviour in the development version of PGFPlots
, dotted, name path = A] gnuplot {
set contour base;
set cntrparam levels discrete 0.003;
unset surface;
set view map;
set isosamples 500;
set samples 500;
splot x + 0.25*y^2 - 1;
};
\addlegendentry{$\mathfrak{Re}(z^2)= 1 - \frac{1}{4} (\mathfrak{Im}(z^2))^2$}
\addplot +[no markers,
raw gnuplot,
very thick,
empty line = jump % not strictly necessary, as this is the default behaviour in the development version of PGFPlots
, dotted] gnuplot {
set contour base;
set cntrparam levels discrete 0.003;
unset surface;
set view map;
set isosamples 500;
set samples 500;
splot x - 1;
};
\addlegendentry{$\mathfrak{Re}(z)= 1$}
\end{axis}
\end{tikzpicture}
答案1
如果要使用路径绘制区域,则需要确保它是连续的。因此,您需要确保用于绘制此路径的函数也是以连续方式计算的。在我们填充它时可以看到,您当前的设置并非如此:
\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis} [
xtick distance = 1,
legend pos = outer north east,
xmin = -3, xmax = 3, ymin = -8, ymax = 8
]
\addplot +[no markers,
raw gnuplot,
very thick,
dotted,
fill = cyan!50
] gnuplot {
set contour base;
set cntrparam levels discrete 0.003;
unset surface;
set view map;
set isosamples 500;
set samples 500;
splot x + 0.25*y^2 - 1;
};
\end{axis}
\end{tikzpicture}
\end{document}
显然,该函数是逐步绘制的,并且具有正和负的部分是值可能以交替方式绘制,无论如何,绘制时都会产生不错的效果,但遗憾的是,我们无法使用任何设置来创建可填充区域。您需要尝试各种设置才能得出gnuplot
一些有用的结果。
但是,我建议您不要使用gnuplot
s 来绘制函数,因为它们都相对简单。此外,您可能应该将函数拆分为曲线,以便获得上分支和下分支:
\documentclass[border=10pt]{standalone}
\usepackage{amssymb}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tikzpicture}
\begin{axis} [
xtick distance = 1,
legend pos = outer north east,
xmin = -3, xmax = 3, ymin = -8, ymax = 8
]
\addplot+[
no markers,
very thick,
dotted,
smooth,
samples = 101,
name path = A upper
] { sqrt( 4 - 4*x ) };
\addlegendentry{$\mathfrak{Re}(z^2) = 1 - \frac{1}{4} (\mathfrak{Im}(z^2))^2$}
\addplot+[
no markers,
very thick,
dotted,
blue,
forget plot,
smooth,
samples = 101,
name path = A lower
] { -1 * sqrt( 4 - 4*x ) };
\addplot+[
no markers,
very thick,
dotted
] coordinates {
(1,\pgfkeysvalueof{/pgfplots/ymin}) (1,\pgfkeysvalueof{/pgfplots/ymax})
};
\addlegendentry{$\mathfrak{Re}(z) = 1$}
\begin{scope}[on background layer]
\path[name path = plot box upper]
(\pgfkeysvalueof{/pgfplots/xmin},0) rectangle
(\pgfkeysvalueof{/pgfplots/xmax},\pgfkeysvalueof{/pgfplots/ymax});
\path[name path = plot box lower]
(\pgfkeysvalueof{/pgfplots/xmin},0) rectangle
(\pgfkeysvalueof{/pgfplots/xmax},\pgfkeysvalueof{/pgfplots/ymin});
\fill[cyan!50, intersection segments = {
of = {A upper and plot box upper},
sequence = {L*[reverse] -- R2}
}] -- cycle;
\fill[cyan!50, intersection segments = {
of = {A lower and plot box lower},
sequence = {L*[reverse] -- R2}
}] -- cycle;
\end{scope}
\end{axis}
\end{tikzpicture}
\end{document}