改善此 TikZ 图片

改善此 TikZ 图片

平均能量损失

\documentclass[12pt]{book}
\usepackage{tikz}
\usetikzlibrary{patterns,shapes.geometric} 
\begin{document} 
\begin{tikzpicture}
\draw[line width=.8pt,->] (-2,0.) -- node[pos=1,right]{}(2,0);
\foreach \x in {-3,-2-1,1,2,3}
\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) ;
\draw[line width=.8pt,->] (0.,-2) -- node[pos=1,above]{}(0,2);
\foreach \t in {-3,-2,-1,1,2,3}
\draw[shift={(0,\t)},color=black] (2pt,0pt) -- (-2pt,0pt) ;
\draw[pattern=north west lines] (-1,1)--(1,1)--(1,-1)--(-1,-1)--(-1,1);
\end{tikzpicture}
 \begin{tikzpicture}
\draw[line width=.8pt,->] (-2,0.) -- node[pos=1,right]{}(2,0);
\foreach \x in {-3,-2-1,1,2,3}
\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) ;
\draw[line width=.8pt,->] (0.,-2) -- node[pos=1,above]{}(0,2);
\foreach \t in {-3,-2,-1,1,2,3}
\draw[shift={(0,\t)},color=black] (2pt,0pt) -- (-2pt,0pt) ;
\draw[pattern=north west lines] (0,0) circle (1 cm);
\end{tikzpicture}
\begin{tikzpicture}
\draw[line width=.8pt,->] (-2,0.) -- node[pos=1,right]{}(2,0);
\foreach \x in {-3,-2-1,1,2,3}
\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) ;
\draw[line width=.8pt,->] (0.,-2) -- node[pos=1,above]{}(0,2);
\foreach \t in {-3,-2,-1,1,2,3}
\draw[shift={(0,\t)},color=black] (2pt,0pt) -- (-2pt,0pt) ;
\draw[pattern=north west lines] (0,1)--(1,0)--(0,-1)--(-1,0)--(0,1);
\end{tikzpicture}
 \end{document}

输出:

在此处输入图片描述

我想删除-并添加1每条边。

答案1

我不知道这是不是想要的?

\documentclass[12pt]{book}
 \usepackage{tikz}
 \usetikzlibrary{patterns,shapes.geometric} 
\begin{document} 
\begin{tikzpicture}
\draw[line width=.8pt,->] (-2,0.) -- node[pos=1,right]{}(2,0);
%\foreach \x in {-3,-2-1,1,2,3}
%raw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) ;
\draw[line width=.8pt,->] (0.,-2) -- node[pos=0.75,above right]{1}(0,2);
%\foreach \t in {-3,-2,-1,1,2,3}
%\draw[shift={(0,\t)},color=black] (2pt,0pt) -- (-2pt,0pt) ;
\draw[pattern=north west lines] (-1,1)--(1,1)--(1,-1)--(-1,-1)--(-1,1);
 \node at (0,-2.25){$d_{\infty}$}; % <---------------
\end{tikzpicture}
 \begin{tikzpicture}
\draw[line width=.8pt,->] (-2,0.) -- node[pos=0.75,above right]{1}(2,0); % <----------- modified
%\foreach \x in {-3,-2-1,1,2,3}
%\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) ;
\draw[line width=.8pt,->] (0.,-2) -- node[pos=0.75,above right]{1}(0,2); %<-------- modified
%\foreach \t in {-3,-2,-1,1,2,3}
%\draw[shift={(0,\t)},color=black] (2pt,0pt) -- (-2pt,0pt) ;
\draw[pattern=north west lines] (0,0) circle (1 cm);
 \node at (0,-2.25){$d_{\infty}$};
\end{tikzpicture}
\begin{tikzpicture}
\draw[line width=.8pt,->] (-2,0.) -- node[pos=0.75,above right]{1}(2,0); % <---------- modified
%\foreach \x in {-3,-2-1,1,2,3}
%\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) ;
\draw[line width=.8pt,->] (0.,-2) -- node[pos=0.75,above right]{1}(0,2); %<------- modified
%\foreach \t in {-3,-2,-1,1,2,3}
%\draw[shift={(0,\t)},color=black] (2pt,0pt) -- (-2pt,0pt) ;
\draw[pattern=north west lines] (0,1)--(1,0)--(0,-1)--(-1,0)--(0,1);
\node at (0,-2.25){$d_{\infty}$};
\end{tikzpicture}
 \end{document}

在此处输入图片描述

答案2

这些小线是由代码中的 for 循环绘制的。如果您不希望它们超出轴的范围,请不要让循环从 -3 运行到 3,而只能从 -2 运行到 2。

如果您还想从轴的边缘删除线条,请将循环进一步限制为 -1 到 1(或完全删除它们,剩余的刻度在矩形边缘上方实际上不可见)

此外,还缺少,,这就是缺少某些行的原因。此外,绘制矩形(和其他几何形状,请参阅下面@marmot 的评论)的语法也可以简化。

\documentclass[12pt]{book}

\usepackage{tikz}
\usetikzlibrary{patterns} 

\begin{document} 

\begin{tikzpicture}
    \draw[line width=.8pt,->] (-2,0.) -- node[pos=1,right]{}(2,0);
    \foreach \x in {-2,-1,1,2}{
        \draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt);
    }
    \draw[line width=.8pt,->] (0.,-2) -- node[pos=1,above]{}(0,2);
    \foreach \t in {-2,-1,1,2}{
        \draw[shift={(0,\t)},color=black] (2pt,0pt) -- (-2pt,0pt);
    }
    \draw[pattern=north west lines] (-1,-1) rectangle (1,1);
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容