将图例向下移动一点

将图例向下移动一点

我有 2 个问题:1- 如何降低图例以使其不覆盖 x 轴 2- 如何避免 x 轴中的 5*10^-2 并得到 0.05

       \documentclass[a4paper,12pt]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english,italian]{babel}
\usepackage{url,amsfonts,epsfig}
\usepackage{amsmath}
\usepackage{caption}
\usepackage{subcaption}
\usepackage[backend=biber]{biblatex}

\usepackage{matlab-prettifier} 

\usepackage{tikz}
\usetikzlibrary{calc,quotes,angles}
\usepgflibrary{arrows.meta}
\usepackage{pgfplots}
\usetikzlibrary{calc}

\begin{document}


\begin{figure}[h]
    \centering
    \begin{subfigure}[b]{0.45\textwidth}
       \centering
    \begin{tikzpicture}
    \begin{axis}[name=plot,
    xmin=0, 
    xmax=0.8, 
    xlabel={$[s]$}, 
    ylabel={$\phi$},
    ymin=0,
    ymax=0.8,
    width=1\textwidth,
    legend style={at={(0.5,-0.17)},anchor=north,legend cell align=left}
    ]
    
    \addplot[black,dashed, domain=0:0.2]{0.9}; \label{gamma_max}
    \addlegendentry{down}
    \addplot[black,dash dot, domain=0:0.2]{0.61}; \label{gamma_min}
    \addlegendentry{down 2}
    \end{axis}
    
    \end{tikzpicture}
    \caption{\textit{model}}
    \label{fig:apertura_max_min}
    \end{subfigure}
    \hfill
    \begin{subfigure}[b]{0.45\textwidth}
       \centering
    \begin{tikzpicture}
    \begin{axis}[name=plot,
    xmin=0, 
    xmax=0.2, 
    xlabel={$[s]$}, 
    ylabel={$Amplitude$},
    ymin=0,ymax=1.0,
    width=1\textwidth,
    legend style={at={(0.5,-0.17)},anchor=north,legend cell align=left,
    xticklabel style={rotate=-90,/pgf/number format/.cd,fixed zerofill,precision=2}}
    ]
    
    \addplot[black,dashed, domain=0:0.2]{0.9}; \label{gamma_max}
    \addlegendentry{lower 1}
    \addplot[black,dash dot, domain=0:0.2]{0.61}; \label{gamma_min}
    \addlegendentry{lower 2}
    \end{axis}
    
    \end{tikzpicture}
    \caption{\textit{model 2}}
    \label{fig:andamento_valvola}
    \end{subfigure}
    \hfill
    \caption{\textit{valve model}}
    \label{fig:costruzione_valvola}
\end{figure}

\end{document}

答案1

如何降低图例以使其不覆盖 x 轴

你可以改变图例位置at={(0.5,-0.45)}通过更改里面的数字legend style=...。您的文件中已经有了这个,我只是更改了数字,以便它们适合您的图。

同样可以做标签,其中也有一些重叠。这次我使用了yshift=-12pt,xshift=65pt中的值xlabel style={at={(0,0)},yshift=-12pt,xshift=65pt}

如何避免 x 轴上的 5*10^-2 并得到 0.05

格式化时x 轴值 xticklabel style=...您必须再添加一个fixed。为了得到 0.05 而不是 5*10^-2,数字格式必须如下/pgf/number format/.cd,fixed,fixed zerofill,precision=2

当我改变图例的位置时,第一个图向下移动了一点,所以我\begin{tikzpicture} ... \end{tikzpicture}\hspace*{0em}\raisebox{0em}{ ... }, 值封装了空间水平移动绘图,值饲养箱垂直移动图。我移动了第一个图10 点看起来它们已经平坦了。

结果 代码更改后的结果

\documentclass[a4paper,12pt]{book}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english,italian]{babel}
\usepackage{url,amsfonts,epsfig}
\usepackage{amsmath}
\usepackage{caption}
\usepackage{subcaption}
\usepackage[backend=biber]{biblatex}
\usepackage{matlab-prettifier} 
\usepackage{tikz}
\usetikzlibrary{calc,quotes,angles}
\usepgflibrary{arrows.meta}
\usepackage{pgfplots}
\usetikzlibrary{calc}

\begin{document}

\begin{figure}[h]
    \centering
    \begin{subfigure}[b]{0.45\textwidth}
    \centering
    \hspace*{0pt}\raisebox{10pt}{\begin{tikzpicture}                        % Edited here
    \begin{axis}[name=plot,
    xmin=0, 
    xmax=0.8, 
    xlabel={$[s]$}, 
    ylabel={$\phi$},
    ymin=0,
    ymax=0.8,
    width=1\textwidth,
    legend style={at={(0.5,-0.35)},anchor=north,legend cell align=left},    % Edited here
    xlabel style={at={(0,0)},yshift=0pt,xshift=65pt}]                       % Edited here
    \addplot[black,dashed, domain=0:0.2]{0.9}; \label{gamma_max}
    \addlegendentry{down}
    \addplot[black,dash dot, domain=0:0.2]{0.61}; \label{gamma_min}
    \addlegendentry{down 2}
    \end{axis}
    \end{tikzpicture}}                                                      % Edited here
    \caption{\textit{model}}
    \label{fig:apertura_max_min}
    \end{subfigure}
    \hfill
    \begin{subfigure}[b]{0.45\textwidth}
    \centering
    \hspace*{0em}\raisebox{0em}{\begin{tikzpicture}                         % Edited here
    \begin{axis}[name=plot,
    xmin=0, 
    xmax=0.2, 
    xlabel={$[s]$}, 
    ylabel={$Amplitude$},
    ymin=0,ymax=1.0,
    width=1\textwidth,
    legend style={at={(0.5,-0.45)},anchor=north,legend cell align=left,     % Edited here
    xticklabel style={rotate=-90,/pgf/number format/.cd,fixed,fixed  zerofill,precision=2}},    % Edited here
    xlabel style={at={(0,0)},yshift=-12pt,xshift=65pt}]                     % Edited here
    \addplot[black,dashed, domain=0:0.2]{0.9}; \label{gamma_max}
    \addlegendentry{lower 1}
    \addplot[black,dash dot, domain=0:0.2]{0.61}; \label{gamma_min}
    \addlegendentry{lower 2}
    \end{axis}
    \end{tikzpicture}}                                                      % Edited here
    \caption{\textit{model 2}}
    \label{fig:andamento_valvola}
    \end{subfigure}
    \hfill
    \caption{\textit{valve model}}
    \label{fig:costruzione_valvola}
\end{figure}

\end{document}

相关内容