在 Tikz 中绘制此图(带负轴)

在 Tikz 中绘制此图(带负轴)

我正在尝试使用 tikz 生成下图:

在此处输入图片描述

然而,我尽了最大的努力却得到了这样的结果(这不是我想要的):

在此处输入图片描述

这里有一个 MWE(有一些文本不同;但这不是问题的重点):

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{fit, calc, matrix, positioning, arrows, intersections, through, backgrounds, patterns}

\begin{document}
\begin{figure}[!htb]
\centering
\begin{tikzpicture}[my plot/.style={thick, smooth, samples=100, domain=0:1}, my grid/.style={densely dotted,opacity=0.5, every node/.style={black,opacity=1}}, my axis/.style={latex-latex},scale=0.75]
\coordinate (start plot) at (0,{(0)});
\coordinate (end plot) at (4,{(4)});
\draw[my axis] ([shift={(-0cm,0cm)}]start plot |- end plot) node[above] {$h_2$} |- node[coordinate](origin){} ([shift={(0cm,-0cm)}]start plot -| end plot) node[right] {$h_1$};
\def\x{0.5}\def\y{4}\def\p{0.55}
\coordinate (Ux) at (4.5,{(0)});
\coordinate (Uy) at (0,{(1.5)});
\coordinate (Ua) at (0,{(6)});
\coordinate (Ub) at (6,{(0)});
\coordinate (Uc) at (3,{(0)});
\coordinate (Ud) at (0,{(3)});
\coordinate (Ue) at (1.5,{(0)});
\coordinate (Uf) at (0,{(4.5)});
\coordinate (Ug) at (0,{(0)});
\coordinate (Uh) at (4.5,{(4.5)});
\coordinate (Ui) at (2,{(2)});
\coordinate (Uj) at (1.5,{(1.5)});
\coordinate (Uk) at (3,{(3)});
\coordinate (Ul) at (1.5,{(4)});
\coordinate (Um) at (4,{(1.5)});
\draw[my grid] (Uy) |- node[left,font=\scriptsize]{$1$} cycle;
\draw[my grid] (Uc) |- node[below,font=\scriptsize]{$2$} cycle;
\draw[my grid] (Ud) |- node[left,font=\scriptsize]{$2$} cycle;
\draw[my grid] (Ue) |- node[below,font=\scriptsize]{$1$} cycle;
\draw[fill] (Ug) circle (2pt);
\draw[fill] (Uj) circle (2pt);
\draw[fill] (Uk) circle (2pt);
\node [below] at (Ug) {\footnotesize{$h(T,R)=H(B,L)$}};
\node [below, xshift=10pt] at (Uj) {\footnotesize{$h(T,L)$}};
\node [right] at (Uk) {\footnotesize{$h(B,R)$}};
\node [left] at (Uj) {\footnotesize{$C(G)$}};
\draw[-] (Uj) -- (Ug);
\draw[-] (Uk) -- (Uj);
\draw[-] (Uj) -- (Ul);
\draw[-] (Uj) -- (Um);
\end{tikzpicture}
\end{document}

我的主要问题是,我根本不知道如何得到带有负 x 和 y 轴的图。有人能帮我得到想要的结果吗?

谢谢你们!

答案1

这是带有类似绘图的一段小代码。我没有更改字体,因为我不知道它的名字。

\documentclass{article}

\usepackage{tikz}

\begin{document}

    \begin{tikzpicture}[scale = 2]
    % axis drawing
    \draw [->] (0,-2) -- (0,2);
    \draw [->] (-2,0) -- (2,0);

    \node[below] at (-1,0) {$-1$};
    \node[below] at (1,0) {$1$};
    \node[left] at (0,-1) {$-1$};
    \node[left] at (0,1) {$1$};
    \node[right] at (2,0) {$h_1$};
    \node[above] at (0,2) {$h_2$};

    % diagonal drawing
    \draw[thick] (-1,1) -- (1,-1);
    \draw[fill] (-1,1) circle [radius=0.05];
    \draw[fill] (1,-1) circle [radius=0.05];

    \node[below right] at (1,-1) {$h(H,H) = h(T,T)$};
    \node[above left] at (-1,1) {$h(T,H) = h(H,T)$};
    \node[below] at (-1,0.7) {$C(G)$};

    % axis 2 drawing
    \draw (1,2.1) -- (1,1) -- (2.1,1);
    \node[right] at (2.1,1) {$R_2=1$};
    \node[above] at (1,2.1) {$R_1=1$};

    \end{tikzpicture}

\end{document}

图形绘制

答案2

我必须承认,我迷失在你的 MWE 中……因此我没有成功找到你在图像元素定位方面犯的错误。相反,我从头开始重新绘制给定的图像(没什么大不了的,它相当简单):

\documentclass [tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows}
\usepackage{sansmath}

\begin{document}
    \begin{tikzpicture}[
every node/.style = {font=\sansmath, color=blue!70!black}
TL/.append style = {font=\sffamily\scriptsize}% TL: Tick Labels
                        ]
% axis
\draw[->] (-3,0)   -- (3,0) node[right] {$h_1$};
\draw[->] (0,-2.5) -- (0,3) node[above] {$h_2$};
% tick
\foreach \i in {-2,-1,1,2}
    \draw (\i,2pt) -- ++ (0,-4pt)   node[TL,below] {\i}
          (2pt,\i) -- ++ (-4pt,0)   node[TL, left] {\i};
% curve (line)
\draw[thick,*-*]    (-1,1) node[left]  {$h(T,H)=h(H,T)$}
                --  (1,-1) node[right] {$h(H,H)=h(T,T)$};       
% R coordinate system?
\draw   (1,2) node[above]  {$R_1=1$}
    |-  (2,1) node[right]  {$R_2=1$};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容