在轴上放置(-)符号并在 pgfplots 中绘制图形

在轴上放置(-)符号并在 pgfplots 中绘制图形

我需要 pgfplots 在 y 轴上显示 (-) 号,但不知何故它无法读取它。

\documentclass{article}
\usepackage[margin=0.5in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{textcomp}

\usepackage{pgfplots}
\pgfplotsset{width=10cm,compat=1.9}
%\usepgfplotslibrary{external}
%\tikzexternalize

\begin{document}

Plotting from data:

\begin{tikzpicture}
\begin{axis}[ 
title={pressure},
xlabel={r/R},
    ylabel={$\frac{\kappa}{C}\frac{dP_{r}}{dx}$},
    xmin=0, xmax=1.2,
    ymin=0, ymax=-9,
    xtick={0,0.2,0.4,0.6,0.8,1.0,1.2},
    ytick={0,-1,-2,-3,-4,-5,-6,-7,-8,-9}]

\addplot[
    color=blue]
    coordinates {
    (0,-8.289)(0.1,-8.139)(0.2,-7.705)(0.3,-7.036)(0.4,-6.2)(0.5,-5.271)(0.6,-4.315)(0.7,-3.386)(0.8,-2.52)(0.9,-1.739)(1,-1.054)
    };


\end{axis}

\end{tikzpicture}
\end{document}

另外,我想要一个在末尾显示 (fig:something) 的标签,我可以在 pgfplots 中添加这样的标签吗?谢谢

答案1

您不能拥有ymin>ymax。设置ymin=-9ymax=0

至于标签,您可以将图放在图形环境中。

\documentclass{article}
\usepackage[margin=0.5in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{textcomp}

\usepackage{pgfplots}
\pgfplotsset{width=10cm,compat=1.9}
%\usepgfplotslibrary{external}
%\tikzexternalize

\begin{document}

Plotting from data:

\begin{figure}[h]
\centering
\begin{tikzpicture}[trim axis left]
\begin{axis}[ 
title={pressure},
xlabel={r/R},
    ylabel={$\frac{\kappa}{C}\frac{dP_{r}}{dx}$},
    xmin=0, xmax=1.2,
    ymin=-9, ymax=0,
    xtick={0,0.2,0.4,0.6,0.8,1.0,1.2},
    ytick={0,-1,-2,-3,-4,-5,-6,-7,-8,-9}]

\addplot[
    color=blue]
    coordinates {
    (0,-8.289)(0.1,-8.139)(0.2,-7.705)(0.3,-7.036)(0.4,-6.2)(0.5,-5.271)(0.6,-4.315)(0.7,-3.386)(0.8,-2.52)(0.9,-1.739)(1,-1.054)
    };

\end{axis}

\end{tikzpicture}
\caption{Hello world}\label{fig:myplot}
\end{figure}
\end{document}

相关内容