1

我想得到*一个名为 tikz 轴图name = MyAxisMyAxis有不同的长度):

+------------+  +--------+
|            |  | legend |
|   MyAxis   |  |        |
|            |  +--------*
+------------+
   l     o
   a     t
   b     h
   e     e
   l     r
         l
         a
         b
         e
         L

我可以使用来获取MyAxis对象的宽度,MyAxis.east - MyAxis.west但我还找不到一个来确定位置MyAxis.legend.eastMyAxis.legend.south east. tikz 支持吗?

进入同一方向的第二个问题是我是否可以确定对象south的最长 x 轴标签的位置MyAxis(标记为' L')?

我需要这些信息来在下面绘制一个新节点(教科书),该节点从以下位置开始(1)并结束于(2)

+------------+  +--------+
|            |  | legend |
|   MyAxis   |  |        |
|            |  +--------*
+------------+
   l     o
   a     t
   b     h
   e     e
   l     r
         l
         a
         b
         e
         L

1------------------------+
| text                   |
+------------------------2

一个最小的工作示例如下

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{filecontents}
\usetikzlibrary{calc}

\begin{document}
\begin{filecontents}{testdata.csv}
  1,  2,  4,  8
  10, 20, 30, 40
  40, 60, 80, 100
  15, 35, 20, 10
\end{filecontents}

\pgfplotstableread[col sep=comma]{testdata.csv}\mytable

\begin{tikzpicture}
\begin{axis}[
name=MyAxis,
width=2\textwidth,
height=.8\textwidth,
legend pos=outer north east,
ybar = 0.05cm,
bar width = 3pt,
ymajorgrids=true,
xticklabel style={rotate=45,anchor=east},
xticklabels={group A, group B, group C, group extra},
xtick=data,
]
\addplot table[x expr=\coordindex, y index=1]{\mytable};
\addplot table[x expr=\coordindex, y index=2]{\mytable};
\addplot table[x expr=\coordindex, y index=3]{\mytable};
\legend{Threads=1,Threads=2,Threads=4,Threads=8}
\end{axis}
\path let \p1=(MyAxis.west), \p2=(MyAxis.east) in node[draw, below
  right, align=left, text=black, text width=\x2-\x1-10pt, minimum
  width=\x2-\x1]
at ($(MyAxis.south west)-(0,50pt)$) {%
Text};
\end{tikzpicture}
\end{document}

提前谢谢了!

4

1 回答 1

0

由于您的图例位于图片的最边缘,因此我将使用当前的边界框:

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{filecontents}
\usetikzlibrary{calc}

\begin{document}
\begin{filecontents}{testdata.csv}
  1,  2,  4,  8
  10, 20, 30, 40
  40, 60, 80, 100
  15, 35, 20, 10
\end{filecontents}

\pgfplotstableread[col sep=comma]{testdata.csv}\mytable

\begin{tikzpicture}
\begin{axis}[
name=MyAxis,
width=2\textwidth,
height=.8\textwidth,
legend pos=outer north east,
ybar = 0.05cm,
bar width = 3pt,
ymajorgrids=true,
xticklabel style={rotate=45,anchor=east},
xticklabels={group A, group B, group C, group extra},
xtick=data,
]
\addplot table[x expr=\coordindex, y index=1]{\mytable};
\addplot table[x expr=\coordindex, y index=2]{\mytable};
\addplot table[x expr=\coordindex, y index=3]{\mytable};
\legend{Threads=1,Threads=2,Threads=4,Threads=8}
\end{axis}
\path let \p1=(MyAxis.west), \p2=(current bounding box.south east) in node[draw, below
  right, align=left, text=black, text width=\x2-\x1-10pt, minimum
  width=\x2-\x1]
at ($(MyAxis.south west)-(0,50pt)$) {%
Text};
\end{tikzpicture}
\end{document}

在此处输入图像描述

于 2021-12-14T14:33:30.153 回答