問題:使用座標系 axis cs 將使用範圍的 tikz-draw 放置在 axis 環境內。
在下面的程式碼之前更好地解釋了這個問題,這是目前實現的不好的解決方案。
\documentclass[12pt]{report}
\usepackage[portuges, brazilian]{babel} % Hiphenação em portugues
\usepackage{graphics} % Suporte padrão para gráficos
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{pgfplots}
\pgfplotsset{grid=major,compat=1.11}
\begin{document}
\begin{figure}[!htb]
\centering
\begin{tikzpicture}
\pgfmathsetmacro{\Ffactor}{0.6}
\coordinate (car1) at (0.50,1.95);
\begin{scope} [rotate around={-25:(car1)}]
\draw[fill=yellow] (car1) + ($\Ffactor*(-0.250, 0.100)$) rectangle + ($\Ffactor*(0.250,-0.100)$);
\draw[fill=black] (car1) ++ ($\Ffactor*(-0.250, 0.100)$) rectangle + ($\Ffactor*( 0.175, 0.075)$); % rear left wheel
\draw[fill=black] (car1) ++ ($\Ffactor*( 0.250, 0.100)$) rectangle + ($\Ffactor*(-0.175, 0.075)$); % front left wheel
\draw[fill=black] (car1) ++ ($\Ffactor*( 0.250,-0.100)$) rectangle + ($\Ffactor*(-0.175,-0.075)$); % front right wheel
\draw[fill=black] (car1) ++ ($\Ffactor*(-0.250,-0.100)$) rectangle + ($\Ffactor*( 0.175,-0.075)$); % rear right wheel
\end{scope}
\begin{axis}[ ]
%
% SOME CODES
%
\end{axis}
\end{tikzpicture} %
\end{figure}
\end{document}
從程式碼中可以看出,提到的tikz-draw是由第一塊程式碼指定的,其位置由座標(car1)設定。接下來是軸環境,在實際實作中,它有一些圖形。我需要透過座標(car1)將 tikz-draw 放置在同一位置,即在某種程度上與軸環境中的圖形相關。目前,透過嘗試和錯誤方法,我花了相當長的時間將 tikz-draw 放置在所需的位置。
我認為可以將與 tikz-draw 相關的程式碼區塊放在 axis 環境中並使用座標軸設定 tikz-draw 位置的座標系如下所示
\begin{tikzpicture}
\begin{axis}[ ]
%
% SOME CODES
%
\pgfmathsetmacro{\Ffactor}{0.6}
\coordinate (car1) at (axis cs: 0.50,1.95); <----------
\begin{scope} [rotate around={-25:(car1)}]
\draw[fill=yellow] (car1) + ($\Ffactor*(-0.250, 0.100)$) rectangle + ($\Ffactor*(0.250,-0.100)$);
\draw[fill=black] (car1) ++ ($\Ffactor*(-0.250, 0.100)$) rectangle + ($\Ffactor*( 0.175, 0.075)$); % rear left wheel
\draw[fill=black] (car1) ++ ($\Ffactor*( 0.250, 0.100)$) rectangle + ($\Ffactor*(-0.175, 0.075)$); % front left wheel
\draw[fill=black] (car1) ++ ($\Ffactor*( 0.250,-0.100)$) rectangle + ($\Ffactor*(-0.175,-0.075)$); % front right wheel
\draw[fill=black] (car1) ++ ($\Ffactor*(-0.250,-0.100)$) rectangle + ($\Ffactor*( 0.175,-0.075)$); % rear right wheel
\end{scope}
%
% SOME CODE
%
\end{axis}
\end{tikzpicture} %
但是,令我驚訝的是,它似乎是軸和範圍環境之間的一些不相容,因為這個新的解決方案檢索了錯誤:
包 pgf 錯誤:沒有名為 car1 的已知形狀。 \begin{scope} [rotate around={-25:(car1)}] 套件 pgf 錯誤:沒有名為 car1 的已知形狀。 \begin{範圍} [圍繞={-25:(car1)}旋轉]
因此,我的問題是如何解決這個問題。
謝謝。
答案1
把\coordinate
裡面的axis
,和scope
後面的\end{axis}
。
\documentclass[12pt]{report}
\usepackage[portuges, brazilian]{babel} % Hiphenação em portugues
\usepackage{graphicx} % Suporte padrão para gráficos
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{pgfplots}
\pgfplotsset{grid=major,compat=1.11}
\begin{document}
\begin{figure}[!htb]
\centering
\begin{tikzpicture}
\pgfmathsetmacro{\Ffactor}{0.6}
\begin{axis}[ ]
%
\coordinate (car1) at (0.5,0.5); % axis cs is default since you have compat=1.11
\addplot coordinates {(0,0)}; % need to have something, or it doesn't work
\end{axis}
\begin{scope} [rotate around={-25:(car1)}]
\draw[fill=yellow] (car1) + ($\Ffactor*(-0.250, 0.100)$) rectangle + ($\Ffactor*(0.250,-0.100)$);
\draw[fill=black] (car1) ++ ($\Ffactor*(-0.250, 0.100)$) rectangle + ($\Ffactor*( 0.175, 0.075)$); % rear left wheel
\draw[fill=black] (car1) ++ ($\Ffactor*( 0.250, 0.100)$) rectangle + ($\Ffactor*(-0.175, 0.075)$); % front left wheel
\draw[fill=black] (car1) ++ ($\Ffactor*( 0.250,-0.100)$) rectangle + ($\Ffactor*(-0.175,-0.075)$); % front right wheel
\draw[fill=black] (car1) ++ ($\Ffactor*(-0.250,-0.100)$) rectangle + ($\Ffactor*( 0.175,-0.075)$); % rear right wheel
\end{scope}
%
\end{tikzpicture} %
\end{figure}
\end{document}