有关 pgfplots 的帮助

有关 pgfplots 的帮助

可以问几个问题吗?我想,在问下一个问题之前,大概要等 40 分钟。

是的,我确实尝试阅读文档,但我找不到那里的信息。

\documentclass[jou,11pt]{apa6}

\usepackage[american]{babel}
\usepackage{csquotes}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\pgfplotsset{width=7cm,compat=newest}
\usepgfplotslibrary{statistics}
\usepackage[style=apa,sortcites=true,sorting=nyt,backend=biber]{biblatex}
\DeclareLanguageMapping{american}{american-apa}

\title{Title content}
\shorttitle{A short title}
\author{Authors}
\affiliation{Affliated institution}
\leftheader{Author 1}
\abstract{Abstract content}

\begin{document}
\maketitle
\section{Content}

\begin{figure}[h!]
\begin{tikzpicture}
\begin{axis}[
    ylabel=RGB Value]
        \addplot table [y=out r, x=out x]{fly_data_out.csv};

        \addplot table [y=out g, x=out x]{fly_data_out.csv};

        \addplot table [y=out b, x=out x]{fly_data_out.csv};

\end{axis}
\end{tikzpicture}
\end{figure}

\begin{figure}[h!]
\begin{tikzpicture}
\begin{axis}[
    ytick={1,2,3,4},
    yticklabels={Cyan, Magenta, Yellow, Key},
    ]
    \addplot+ [
        boxplot prepared={
            lower whisker=43, lower quartile=54,
            median=59,
            upper quartile=62, upper whisker=72,
        },
    ] coordinates {};

    \addplot+ [
        boxplot prepared={
            lower whisker=23, lower quartile=33,
            median=37,
            upper quartile=41, upper whisker=51,
        },
    ] coordinates {(0,55)};

    \addplot+ [
        boxplot prepared={
            lower whisker=25, lower quartile=37,
            median=41,
            upper quartile=46, upper whisker=58,
        },
    ] coordinates {(0,63)(0,64)(0,67)(0,68)(0,69)};

    \addplot+ [
        boxplot prepared={
            lower whisker=0, lower quartile=3,
            median=5,
            upper quartile=8.5, upper whisker=50,
        },
    ] coordinates {};
\end{axis}
\end{tikzpicture}
\end{figure}

\end{document}
  1. 上面的例子会产生错误:

抱歉,无法从表“ \pgfplotstableread@filename@@table@name”中检索列“out x”。请检查拼写(或引入名称别名)。

我认为我应该\pgfplotstableread在某个地方使用,但我找不到任何关于该信息或任何具体的例子。

.csv 文件的示例:

out x,out r,out g,out b,out c,out m,out y,out k
1,48,51,43,38,28,36,2
2,50,51,44,43,32,38,2
3,55,51,44,47,34,39,3
4,55,54,46,48,35,42,4
5,56,59,47,49,35,43,4
6,58,61,48,50,35,43,5
7,58,63,49,50,36,45,5
8,60,65,49,52,36,46,6
9,61,65,50,52,36,46,6
10,61,65,50,53,36,46,7
  1. 一旦数据图问题得到纠正,有没有办法删除 x 刻度和标签?

  2. 另外,我如何确保情节呈现平滑的曲线?

  3. 我可以更改单个数据曲线/箱线图的颜色吗?我该怎么做?

  4. 箱线图中的异常值形状不同。我可以将它们全部改为像图 1 那样的实心圆吗?

谢谢。

答案1

至于你的问题:

  1. 您必须说明pgfplots列分隔符是什么。为此,我添加了col sep=comma
  2. 您可以通过说 来删除勾号xtick=\empty,ytick=\empty
  3. 为了使曲线平滑,请添加smooth轴选项。
  4. 是的,你可以改变颜色。我添加了redcyan
  5. 您可以通过说 来获得完整的圆圈mark=*

这是代码(我删除了不相关的包):

\documentclass[jou,11pt]{apa6}
%\usepackage[american]{babel}
%\usepackage{csquotes}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\pgfplotsset{width=7cm,compat=newest}
\usepgfplotslibrary{statistics}
%\usepackage[style=apa,sortcites=true,sorting=nyt,backend=biber]{biblatex}
%\DeclareLanguageMapping{american}{american-apa}
\usepackage{filecontents}
\begin{filecontents*}{fly_data_out.csv}
out x,out r,out g,out b,out c,out m,out y,out k
1,48,51,43,38,28,36,2
2,50,51,44,43,32,38,2
3,55,51,44,47,34,39,3
4,55,54,46,48,35,42,4
5,56,59,47,49,35,43,4
6,58,61,48,50,35,43,5
7,58,63,49,50,36,45,5
8,60,65,49,52,36,46,6
9,61,65,50,52,36,46,6
10,61,65,50,53,36,46,7
\end{filecontents*}

\title{Title content}
\shorttitle{A short title}
\author{Authors}
\affiliation{Affliated institution}
\leftheader{Author 1}
\abstract{Abstract content}

\begin{document}
\maketitle
\section{Content}

\begin{figure}[h!]
\begin{tikzpicture}
\begin{axis}[xtick=\empty,ytick=\empty,smooth,
    ylabel=RGB Value]
        \addplot table [col sep=comma,y=out r, x=out x]{fly_data_out.csv};

        \addplot[red,mark=*] table [col sep=comma,y=out g, x=out x]{fly_data_out.csv};

        \addplot[cyan,mark=*] table [col sep=comma,y=out b, x=out x]{fly_data_out.csv};

\end{axis}
\end{tikzpicture}
\end{figure}

\begin{figure}[h!]
\begin{tikzpicture}
\begin{axis}[xtick=\empty,ytick=\empty,
    ytick={1,2,3,4},
    yticklabels={Cyan, Magenta, Yellow, Key},
    ]
    \addplot+ [
        boxplot prepared={
            lower whisker=43, lower quartile=54,
            median=59,
            upper quartile=62, upper whisker=72,
        },
    ] coordinates {};

    \addplot+ [
        boxplot prepared={
            lower whisker=23, lower quartile=33,
            median=37,
            upper quartile=41, upper whisker=51,
        },
    ] coordinates {(0,55)};

    \addplot+ [
        boxplot prepared={
            lower whisker=25, lower quartile=37,
            median=41,
            upper quartile=46, upper whisker=58,
        },
    ] coordinates {(0,63)(0,64)(0,67)(0,68)(0,69)};

    \addplot+ [
        boxplot prepared={
            lower whisker=0, lower quartile=3,
            median=5,
            upper quartile=8.5, upper whisker=50,
        },
    ] coordinates {};
\end{axis}
\end{tikzpicture}
\end{figure}

\end{document}

在此处输入图片描述

相关内容