我使用了一些准备代码,结果如下所示。要填充球内,我们应该怎么做?
\documentclass[border=3mm]{standalone}
\usepackage{pgfplots}
% Unit circle plot style
\pgfplotsset{unit circle/.style={width=4cm,height=4cm,axis lines=middle,xtick=\empty,ytick=\empty,axis equal,enlargelimits,xmax=1,ymax=1,xmin=-1,ymin=-1,domain=0:pi/2}}
\begin{document}
\begin{tikzpicture}
\coordinate (prev); % Store previous plot position
\foreach \p / \t in {2/1, 1/2, 0.0001/\infty} { % Loop through the plots to draw
% \p is the exponent in the function to plot
% \t is the p parameter to print
\begin{axis}[at={(prev)},unit circle,anchor=west]
\foreach \ss in {1,-1} {
\foreach \cs in {1,-1} {
\addplot[] ({\cs*(cos(deg(x)))^\p},{\ss*(sin(deg(x))^\p});
}
}
\end{axis}
\node[below=0.5cm, anchor=base] at (current axis.south) {$p=\t$}; % Print p
\coordinate[right=0.5cm] (prev) at (current axis.east) ; % Set position for next plot
}
\end{tikzpicture}
\end{document}
答案1
问题终于解决了。我只改了一行!
\addplot[fill=gray] ({\cs*(cos(deg(x)))^\p},{\ss*(sin(deg(x))^\p})\closedcycle;
答案2
这可以通过 tkz-euclide 轻松实现——下面有一个粗略的相似之处,可以适应上述要求
\documentclass{article} % or another class
\usepackage{xcolor} % before tikz or tkz-euclide if necessary
\usepackage{tkz-euclide} % no need to load TikZ
\usepackage{multirow}
\usetikzlibrary{babel} %if there are problems with the active characters
\begin{document}
\begin{tikzpicture}
\foreach \d/\x/\y in {2/-2/0,3/1/0,4/5/0}{%
\tkzDefPoint(\x,\y){K}
\tkzDefShiftPoint[K](0:\d){M}
\tkzDefSquare(K,M)\tkzGetPoints{N}{O}
\tkzDrawPolygon[color=red,fill=green](K,M,N,O)
\tkzLabelSegment[below](K,M){Square side=\d cm}
}
\end{tikzpicture}
\end{document}
编辑
\documentclass{article} % or another class
\usepackage{xcolor} % before tikz or tkz-euclide if necessary
\usepackage{tkz-euclide} % no need to load TikZ
\usepackage{multirow}
\usetikzlibrary{babel} %if there are problems with the active characters
\begin{document}
\begin{tikzpicture}\hspace{-4cm}
\tkzInit[xmax=2,ymax=3,xmin=-2.5,ymin=-3]
\tkzDrawXY[label={}]
\tkzDefPoint(-2,-2){K}
\tkzDefShiftPoint[K](0:4){M}
\tkzDefSquare(K,M)\tkzGetPoints{N}{O}
\tkzDrawPolygon[color=red,fill=green](K,M,N,O)
%\tkzLabelSegment[below, yshift=-1.5cm](K,M){p=1}
\end{tikzpicture}
\begin{tikzpicture}\hspace{-3cm}
\tkzInit[xmax=2.5,ymax=3,xmin=-3,ymin=-3]
\tkzDrawXY[label={}]
\tkzDefPoint(0,-(sqrt(18))/2){K}
\tkzDefShiftPoint[K](45:3){M}
\tkzDefSquare(K,M)\tkzGetPoints{N}{O}
\tkzDrawPolygon[color=red,fill=green](K,M,N,O)
%\tkzLabelPoint[below, yshift=0cm](K){p=2}
\end{tikzpicture} \hspace{-2cm}
\begin{tikzpicture}
\tkzInit[xmax=2.5,ymax=3,xmin=-2.5,ymin=-3]
\tkzDrawXY[label={}]
\tkzDefPoint(0,0){K}
\tkzDefShiftPoint[K](0:2){M}
\tkzDrawCircle[color=red,fill=green](K,M)
%\tkzLabelPoint[below, yshift=-2cm](K){p=}
\end{tikzpicture}
\end{document}