如何将直方图放入 tikzpicture 节点内

如何将直方图放入 tikzpicture 节点内

我想修复 x 轴标签位置,还想知道如何重新定位矩形内的直方图,如边距中心或其他可行解决方案

\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\tikzset{myblock/.style = {rectangle, draw, minimum height=3cm}
}
  \begin{tikzpicture}
    \node (foo)[myblock]{
       \begin{tikzpicture}
       \begin{axis}[
       ybar=-0.10cm,
       axis x line*=bottom,
       axis y line*=left,
       height=3.5cm, width=3.4cm,
       bar width=0.1cm,
       symbolic x coords={topic1,topic2,topic3},
       %xtick={topic1,topic2,topic3},
       label style={font=\tiny},
       tick label style={font=\tiny}]
    \addplot[BlueGreen,fill] coordinates {(topic1,0.4)};
    \addplot[Cyan,fill] coordinates {(topic2,0.5)};
    \addplot[ForestGreen,fill] coordinates {(topic3,0.1)};
      
    \end{axis}
    \end{tikzpicture}     
};
\node (bar)[myblock,right of=foo,xshift=5cm]{bar};
\draw[->] ($(foo.north east)!0.25!(foo.south east)$) -- node[below] {arrow text} ($(bar.north west)!0.25!(bar.south west)$);
\draw[->] ($(foo.north east)!0.5!(foo.south east)$) -- node[below] {arrow text} ($(bar.north west)!0.5!(bar.south west)$);
\draw[->] ($(foo.north east)!0.75!(foo.south east)$) -- node[below] {arrow text} ($(bar.north west)!0.75!(bar.south west)$);
% more arrows here
\end{tikzpicture}
\newpage
\end{document}

在此处输入图片描述

答案1

在此处输入图片描述

\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{positioning,calc, fit}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
    \tikzset{myblock/.style = {rectangle, draw, minimum height=3cm}
    }
    \begin{tikzpicture}
%       \node (foo)[myblock]{
%           \begin{tikzpicture}
                \begin{axis}[
                    ybar=-0.10cm,
                    axis x line*=bottom,
                    axis y line*=left,
                    height=3.5cm, width=3.4cm,
                    bar width=0.1cm,
                    symbolic x coords={topic1,topic2,topic3},
                    %xtick={topic1,topic2,topic3},
                    label style={font=\tiny},
                    tick label style={font=\tiny}]
                    \addplot[BlueGreen,fill] coordinates {(topic1,0.4)};
                    \addplot[Cyan,fill] coordinates {(topic2,0.5)};
                    \addplot[ForestGreen,fill] coordinates {(topic3,0.1)};
                    
                \end{axis}
            (bounding box)
            \node[draw=red, fit=(current bounding box)]{};
            \draw(current bounding box.east)--++(2,0);
%           \end{tikzpicture}     
%       };
%       \node (bar)[myblock,right of=foo,xshift=5cm]{bar};
%       \draw[->] ($(foo.north east)!0.25!(foo.south east)$) -- node[below] {arrow text} ($(bar.north west)!0.25!(bar.south west)$);
%       \draw[->] ($(foo.north east)!0.5!(foo.south east)$) -- node[below] {arrow text} ($(bar.north west)!0.5!(bar.south west)$);
%       \draw[->] ($(foo.north east)!0.75!(foo.south east)$) -- node[below] {arrow text} ($(bar.north west)!0.75!(bar.south west)$);
        % more arrows here
    \end{tikzpicture}
%   \newpage
\end{document}

相关内容