将 tikzplotlib 生成的图片加载到 latex 中会改变绘图上的轴

将 tikzplotlib 生成的图片加载到 latex 中会改变绘图上的轴

我使用 tikzplotlib 生成了一个图。当我将 .tex 文件加载到 latex 中时,它会将 y 轴添加到 10^-2,但我不知道为什么。将图片保存为 .png 后看起来像(y 轴上方没有 10^-2):

在此处输入图片描述

现在将其加载到乳胶中看起来像:(分别更改 ymax = 0.1 和 ytick 和 yticklabels 会删除 10^-2,但我想保持轴原样。

在此处输入图片描述

.tex 文件的代码:

% This file was created by tikzplotlib v0.9.2.
\begin{tikzpicture}

\definecolor{color0}{rgb}{0.12156862745098,0.466666666666667,0.705882352941177}

\begin{axis}[
axis line style={white!80!black},
height=250,
legend cell align={left},
legend style={fill opacity=0.8, draw opacity=1, text opacity=1, draw=none},
tick align=outside,
tick pos=left,
title={Fitted Interest Rate Curve on 02/01/2008},
width=383.69687,
x grid style={white!80!black},
xlabel={Time to Maturity in Months},
xmajorgrids,
xmin=-1.2, xmax=25.2,
xtick style={color=white!15!black},
y grid style={white!80!black},
ylabel={Interest Rates},
ymajorgrids,
ymin=0.0250435891766118, ymax=0.0476518762980953,
ytick style={color=white!15!black},
ytick={0.025,0.03,0.035,0.04,0.045,0.05},
yticklabels={0.025,0.030,0.035,0.040,0.045,0.050}
]
\addplot [only marks, mark=*, draw=black, fill=black, colormap/blackwhite]
table{%
x                      y
1.6551724137931 0.0346710574892205
1.6551724137931 0.0347008474180928
1.6551724137931 0.034452434761201
1.6551724137931 0.0345074315390218
1.6551724137931 0.0356950672992409
1.6551724137931 0.0350726257693646
1.6551724137931 0.0354015217296337
1.6551724137931 0.0329696933373616
1.6551724137931 0.0342204678808839
1.6551724137931 0.0349538612700615
1.6551724137931 0.0347511186084649
1.6551724137931 0.0355341693698792
1.6551724137931 0.0355677443042893
1.6551724137931 0.0342486231861851
1.6551724137931 0.0345364557835365
1.6551724137931 0.0352265545130207
1.6551724137931 0.0343671606404151
1.6551724137931 0.0349078604166375
1.6551724137931 0.0351035354040597
1.6551724137931 0.035186641429049
1.6551724137931 0.0351456498305472
1.6551724137931 0.0350292140875292
1.6551724137931 0.0348300449318321
1.6551724137931 0.0343087896940228
1.6551724137931 0.0348774553273836
2.6551724137931 0.0372207255944761
2.6551724137931 0.0371342302507912
2.6551724137931 0.0371195183157901
2.6551724137931 0.0368614472657368
2.6551724137931 0.0373783125077458
2.6551724137931 0.0367702911888243
2.6551724137931 0.0371043860872954
2.6551724137931 0.0369499628104391
2.6551724137931 0.0369761069754751
2.6551724137931 0.03694099367746
2.6551724137931 0.0373037626052257
2.6551724137931 0.0369929270737534
4.82758620689655 0.0392460020674819
4.82758620689655 0.0397257721373456
4.82758620689655 0.0393306173400544
4.82758620689655 0.0392499043039621
4.82758620689655 0.0395573997765535
4.82758620689655 0.0393909298975727
4.82758620689655 0.0394090266756156
4.82758620689655 0.039228309713301
4.82758620689655 0.0392711838196148
4.82758620689655 0.0394855925749731
4.82758620689655 0.0391153562996228
4.82758620689655 0.0393891970241044
4.82758620689655 0.0395410927326103
4.82758620689655 0.039593888905118
4.82758620689655 0.0394478485415212
7.96551724137931 0.0392858437447151
7.96551724137931 0.039165494561136
7.96551724137931 0.0390047389463583
7.96551724137931 0.0394744751235327
7.96551724137931 0.0391271036781375
7.96551724137931 0.0392443799730593
7.96551724137931 0.0391792359419029
7.96551724137931 0.0392157863805116
11.1034482758621 0.0384215069896163
11.1034482758621 0.0386263914657472
11.1034482758621 0.038916937967733
11.1034482758621 0.0370642548103912
11.1034482758621 0.0384369446212334
11.1034482758621 0.0385167174293946
11.1034482758621 0.038375552844722
11.1034482758621 0.038601490935288
11.1034482758621 0.0384585704227411
17.3793103448276 0.037192466749433
17.3793103448276 0.0370695553285755
17.3793103448276 0.0371502050653449
17.3793103448276 0.037232446288149
17.3793103448276 0.037105460087768
23.6551724137931 0.0365432026489241
23.6551724137931 0.0366086455048819
23.6551724137931 0.0365562404103965
23.6551724137931 0.0365768320000762
};
\addlegendentry{Calcualted Interest Rates}
\addplot [only marks, mark=square*, draw=red, fill=red, colormap/blackwhite]
table{%
x                      y
1.6551724137931 0.0348774553273836
2.6551724137931 0.0370486565805244
4.82758620689655 0.0393909298975727
7.96551724137931 0.0391975111612073
11.1034482758621 0.0384585704227411
17.4269248937175 0.0371502050653449
23.7199811053377 0.0365665362052363
};
\addlegendentry{Median of Calculated Interest Rates}
\addplot [only marks, mark=diamond*, draw=green!50!black, fill=green!50!black, colormap/blackwhite]
table{%
x                      y
1 0.0357576
3 0.037056
6 0.0383455
9 0.0389574
};
\addlegendentry{Retrieved Interest Rates}
\addplot [semithick, color0]
table {%
0 0.0349610571066018
1 0.0357575611471685
3 0.037056016776056
6 0.0383454987818585
9 0.0389573863539215
12 0.0390021255369341
15 0.0385749689558801
18 0.0377579390807873
21 0.0366215454782495
24 0.0352262863413252
};
\addlegendentry{Fitted Interest Rate Curve}
\end{axis}

\end{tikzpicture}

答案1

只需添加scaled y ticks=false,

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}

\begin{document}
\begin{tikzpicture}

\definecolor{color0}{rgb}{0.12156862745098,0.466666666666667,0.705882352941177}

\begin{axis}[scaled y ticks=false,
axis line style={white!80!black},
height=250,
legend cell align={left},
legend style={fill opacity=0.8, draw opacity=1, text opacity=1, draw=none},
tick align=outside,
tick pos=left,
title={Fitted Interest Rate Curve on 02/01/2008},
width=383.69687,
x grid style={white!80!black},
xlabel={Time to Maturity in Months},
xmajorgrids,
xmin=-1.2, xmax=25.2,
xtick style={color=white!15!black},
y grid style={white!80!black},
ylabel={Interest Rates},
ymajorgrids,
ymin=0.0250435891766118, ymax=0.0476518762980953,
ytick style={color=white!15!black},
ytick={0.025,0.03,0.035,0.04,0.045,0.05},
yticklabels={0.025,0.030,0.035,0.040,0.045,0.050}
]
\addplot [only marks, mark=*, draw=black, fill=black, colormap/blackwhite]
table{%
x                      y
1.6551724137931 0.0346710574892205
1.6551724137931 0.0347008474180928
1.6551724137931 0.034452434761201
1.6551724137931 0.0345074315390218
1.6551724137931 0.0356950672992409
1.6551724137931 0.0350726257693646
1.6551724137931 0.0354015217296337
1.6551724137931 0.0329696933373616
1.6551724137931 0.0342204678808839
1.6551724137931 0.0349538612700615
1.6551724137931 0.0347511186084649
1.6551724137931 0.0355341693698792
1.6551724137931 0.0355677443042893
1.6551724137931 0.0342486231861851
1.6551724137931 0.0345364557835365
1.6551724137931 0.0352265545130207
1.6551724137931 0.0343671606404151
1.6551724137931 0.0349078604166375
1.6551724137931 0.0351035354040597
1.6551724137931 0.035186641429049
1.6551724137931 0.0351456498305472
1.6551724137931 0.0350292140875292
1.6551724137931 0.0348300449318321
1.6551724137931 0.0343087896940228
1.6551724137931 0.0348774553273836
2.6551724137931 0.0372207255944761
2.6551724137931 0.0371342302507912
2.6551724137931 0.0371195183157901
2.6551724137931 0.0368614472657368
2.6551724137931 0.0373783125077458
2.6551724137931 0.0367702911888243
2.6551724137931 0.0371043860872954
2.6551724137931 0.0369499628104391
2.6551724137931 0.0369761069754751
2.6551724137931 0.03694099367746
2.6551724137931 0.0373037626052257
2.6551724137931 0.0369929270737534
4.82758620689655 0.0392460020674819
4.82758620689655 0.0397257721373456
4.82758620689655 0.0393306173400544
4.82758620689655 0.0392499043039621
4.82758620689655 0.0395573997765535
4.82758620689655 0.0393909298975727
4.82758620689655 0.0394090266756156
4.82758620689655 0.039228309713301
4.82758620689655 0.0392711838196148
4.82758620689655 0.0394855925749731
4.82758620689655 0.0391153562996228
4.82758620689655 0.0393891970241044
4.82758620689655 0.0395410927326103
4.82758620689655 0.039593888905118
4.82758620689655 0.0394478485415212
7.96551724137931 0.0392858437447151
7.96551724137931 0.039165494561136
7.96551724137931 0.0390047389463583
7.96551724137931 0.0394744751235327
7.96551724137931 0.0391271036781375
7.96551724137931 0.0392443799730593
7.96551724137931 0.0391792359419029
7.96551724137931 0.0392157863805116
11.1034482758621 0.0384215069896163
11.1034482758621 0.0386263914657472
11.1034482758621 0.038916937967733
11.1034482758621 0.0370642548103912
11.1034482758621 0.0384369446212334
11.1034482758621 0.0385167174293946
11.1034482758621 0.038375552844722
11.1034482758621 0.038601490935288
11.1034482758621 0.0384585704227411
17.3793103448276 0.037192466749433
17.3793103448276 0.0370695553285755
17.3793103448276 0.0371502050653449
17.3793103448276 0.037232446288149
17.3793103448276 0.037105460087768
23.6551724137931 0.0365432026489241
23.6551724137931 0.0366086455048819
23.6551724137931 0.0365562404103965
23.6551724137931 0.0365768320000762
};
\addlegendentry{Calcualted Interest Rates}
\addplot [only marks, mark=square*, draw=red, fill=red, colormap/blackwhite]
table{%
x                      y
1.6551724137931 0.0348774553273836
2.6551724137931 0.0370486565805244
4.82758620689655 0.0393909298975727
7.96551724137931 0.0391975111612073
11.1034482758621 0.0384585704227411
17.4269248937175 0.0371502050653449
23.7199811053377 0.0365665362052363
};
\addlegendentry{Median of Calculated Interest Rates}
\addplot [only marks, mark=diamond*, draw=green!50!black, fill=green!50!black, colormap/blackwhite]
table{%
x                      y
1 0.0357576
3 0.037056
6 0.0383455
9 0.0389574
};
\addlegendentry{Retrieved Interest Rates}
\addplot [semithick, color0]
table {%
0 0.0349610571066018
1 0.0357575611471685
3 0.037056016776056
6 0.0383454987818585
9 0.0389573863539215
12 0.0390021255369341
15 0.0385749689558801
18 0.0377579390807873
21 0.0366215454782495
24 0.0352262863413252
};
\addlegendentry{Fitted Interest Rate Curve}
\end{axis}

\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容