在 pgfplots 中调整轴大小

在 pgfplots 中调整轴大小

我有一张图,其中 y 轴上的两个值非常接近。我想在它们之间添加空间以使它们更明显,但又不使轴本身太大。这可能吗?

梅威瑟:

\begin{tikzpicture}[scale=0.75]
\begin{axis}[
  width=10cm,
  axis x line=center,
  axis y line=center,
  xtick={6.78, 12},
  ytick={-35.81, 0.67, 1.145, 29.59},
  xlabel={$x$},
  ylabel={$y$},
  xlabel style={above right},
  ylabel style={above left},
  xmin=0,
  xmax=15,
  ymin=-40,
  ymax=40]
 \addplot[thick, blue] plot coordinates {(0,0.67) (6.78, 1.145)};
 \addplot[thick, blue] plot coordinates {(6.78, 1.145) (12, 29.59)};
 \addplot[dotted, blue] plot coordinates {(0,1.145) (6.78, 1.145)};
 \addplot[dotted, blue] plot coordinates {(6.78, 1.145) (0, -35.81)};
 \addplot[dotted, blue] plot coordinates {(6.78, 1.145) (12, 1.51)};
 \end{axis}
\end{tikzpicture}

答案1

0.67您可以在和处移动刻度标签1.145

在此处输入图片描述

代码:

\documentclass[margin=5pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}

\begin{document}

\begin{tikzpicture}[scale=0.75]
\begin{axis}[
  width=10cm,
  axis x line=center,
  axis y line=center,
  xtick={6.78, 12},
  ytick={-35.81, 0.67, 1.145, 29.59},
  yticklabel={%
    \ifdim \tick pt=0.67pt%
        \raisebox{-\baselineskip}{\pgfmathprintnumber{\tick}}%
    \else 
      \ifdim \tick pt=1.145pt%
        \raisebox{\ht\strutbox}{\pgfmathprintnumber{\tick}}%
      \else
        \pgfmathprintnumber{\tick}%
      \fi
    \fi
  },
  xlabel={$x$},
  ylabel={$y$},
  xlabel style={above right},
  ylabel style={above left},
  xmin=0,
  xmax=15,
  ymin=-40,
  ymax=40]
 \addplot[thick, blue] plot coordinates {(0,0.67) (6.78, 1.145)};
 \addplot[thick, blue] plot coordinates {(6.78, 1.145) (12, 29.59)};
 \addplot[dotted, blue] plot coordinates {(0,1.145) (6.78, 1.145)};
 \addplot[dotted, blue] plot coordinates {(6.78, 1.145) (0, -35.81)};
 \addplot[dotted, blue] plot coordinates {(6.78, 1.145) (12, 1.51)};
 \end{axis}
\end{tikzpicture}
\end{document}

相关内容