为了清晰起见,在 Python 中执行以下代码会生成一个带有较小子图的图形:
import numpy as np
import matplotlib.pyplot as plt
import tikzplotlib
x = np.array([1, 1.1, 2, 3])
y1 = np.array([.1, .05, 10, 9])
y2 = np.array([.08, .12, 9, 8])
xzoom = x[0:2]
y1zoom = y1[0:2]
y2zoom = y2[0:2]
plt.figure(1)
plt.clf()
plt.plot(x, y1, 'b.-')
plt.plot(x, y2, 'r.-')
sub_axes = plt.axes([.5,.2,.3,.3])
sub_axes.plot(xzoom, y1zoom, 'b.-')
sub_axes.plot(xzoom, y2zoom, 'r.-')
plt.show()
tikzplotlib.save('fig1.tex')
生成的 .tex 文件
% This file was created with tikzplotlib v0.10.1.
\begin{tikzpicture}
\definecolor{darkgray176}{RGB}{176,176,176}
\begin{axis}[
tick align=outside,
tick pos=left,
x grid style={darkgray176},
xmin=0.9, xmax=3.1,
xtick style={color=black},
y grid style={darkgray176},
ymin=-0.4475, ymax=10.4975,
ytick style={color=black}
]
\addplot [semithick, blue, mark=*, mark size=3, mark options={solid}]
table {%
1 0.1
1.1 0.05
2 10
3 9
};
\addplot [semithick, red, mark=*, mark size=3, mark options={solid}]
table {%
1 0.08
1.1 0.12
2 9
3 8
};
\end{axis}
\begin{axis}[
tick align=outside,
tick pos=left,
x grid style={darkgray176},
xmin=0.995, xmax=1.105,
xtick style={color=black},
y grid style={darkgray176},
ymin=0.0465, ymax=0.1235,
ytick style={color=black}
]
\addplot [semithick, blue, mark=*, mark size=3, mark options={solid}]
table {%
1 0.1
1.1 0.05
};
\addplot [semithick, red, mark=*, mark size=3, mark options={solid}]
table {%
1 0.08
1.1 0.12
};
\end{axis}
\end{tikzpicture}
但在 LaTeX 中,结果显示为:
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\input{fig1.tex}
\end{document}
两个单独的部分axes
只是简单地叠加在一起。我认为子图的原始坐标丢失了。我该如何手动将它们添加到 .tex 代码中,以便将子图重新定位到正确的位置?