我想根据我的数据绘制一条回归线,并在绘图中添加图例。图例中的标记形状正常,但回归线上的标记形状错误。我哪里做错了?
\documentclass[article]{standalone}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\definecolor{webgreen}{rgb}{0,.5,0}
\definecolor{webblue}{rgb}{0,0,.8}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
legend style={
cells={anchor=west},
legend pos={south east},
},
xmin=0, xmax=51,% x scale
ymode=log,
ymin=5e-8, ymax=2e-5, % y scale
scatter/classes={%
MPP={mark=diamond*,draw=webgreen},Cluster={mark=triangle*,draw=webblue}, MPPR={mark=diamond,draw=webgreen},ClusterR={mark=triangle,draw=webblue}}]
\addplot[scatter,only marks,%
scatter src=explicit symbolic]%
table[meta=label] {
x y label
3 9.656E-07 MPP
4 1.096E-07 MPP
6 2.191E-07 MPP
45 1.052E-06 MPP
49 4.131E-06 MPP
50 4.682E-06 MPP
};
\addlegendentry{MPP data in 2016}
\addplot[scatter,only marks,%
scatter src=explicit symbolic]%
table[meta=label] {
x y label
2 1.991E-07 Cluster
5 1.040E-07 Cluster
11 1.225E-06 Cluster
31 1.365E-05 Cluster
33 2.677E-06 Cluster
34 1.718E-06 Cluster
38 1.243E-06 Cluster
39 4.628E-06 Cluster
};
\addlegendentry{C data in 2016}
\addplot table[y={create col/linear regression={y=Y}}, mark=diamond,
meta=label, /pgf/number format/read comma as period
]
{
x Y label
3 9.656E-07 MPPR
4 1.096E-07 MPPR
6 2.191E-07 MPPR
45 1.052E-06 MPPR
49 4.131E-06 MPPR
50 4.682E-06 MPPR
};
\addlegendentry{Regression of MPP in 2016}
\addplot table[y={create col/linear regression={y=Y}}, mark=triangle,
meta=label, /pgf/number format/read comma as period
]
{
x Y label
2 1.991E-07 ClusterR
5 1.040E-07 ClusterR
11 1.225E-06 ClusterR
33 2.677E-06 ClusterR
34 1.718E-06 ClusterR
38 1.243E-06 ClusterR
39 4.628E-06 ClusterR
};
\addlegendentry{Regression in 2016}
\end{axis}
\end{tikzpicture}
\end{document}
答案1
mark=diamond
必须设置为选项\addplot
:
\addplot+[mark=diamond] table[...]{...};
代码:
\documentclass{standalone}
\usepackage{pgfplotstable}% loads also pgfplots
\pgfplotsset{compat=1.15}% <- set a compat; current version is 1.15
\definecolor{webgreen}{rgb}{0,.5,0}
\definecolor{webblue}{rgb}{0,0,.8}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
legend style={
cells={anchor=west},
legend pos={south east},
},
xmin=0, xmax=51,% x scale
ymode=log,
ymin=5e-8, ymax=2e-5, % y scale
scatter/classes={%
MPP={mark=diamond*,draw=webgreen},Cluster={mark=triangle*,draw=webblue}, MPPR={mark=diamond,draw=webgreen},ClusterR={mark=triangle,draw=webblue}}]
\addplot[scatter,only marks,%
scatter src=explicit symbolic]%
table[meta=label] {
x y label
3 9.656E-07 MPP
4 1.096E-07 MPP
6 2.191E-07 MPP
45 1.052E-06 MPP
49 4.131E-06 MPP
50 4.682E-06 MPP
};
\addlegendentry{MPP data in 2016}
\addplot[scatter,only marks,%
scatter src=explicit symbolic]%
table[meta=label] {
x y label
2 1.991E-07 Cluster
5 1.040E-07 Cluster
11 1.225E-06 Cluster
31 1.365E-05 Cluster
33 2.677E-06 Cluster
34 1.718E-06 Cluster
38 1.243E-06 Cluster
39 4.628E-06 Cluster
};
\addlegendentry{C data in 2016}
\addplot+[mark=diamond]table[y={create col/linear regression={y=Y}},
meta=label, /pgf/number format/read comma as period
]
{
x Y label
3 9.656E-07 MPPR
4 1.096E-07 MPPR
6 2.191E-07 MPPR
45 1.052E-06 MPPR
49 4.131E-06 MPPR
50 4.682E-06 MPPR
};
\addlegendentry{Regression of MPP in 2016}
\addplot+[mark=triangle] table[y={create col/linear regression={y=Y}},
meta=label, /pgf/number format/read comma as period
]
{
x Y label
2 1.991E-07 ClusterR
5 1.040E-07 ClusterR
11 1.225E-06 ClusterR
33 2.677E-06 ClusterR
34 1.718E-06 ClusterR
38 1.243E-06 ClusterR
39 4.628E-06 ClusterR
};
\addlegendentry{Regression in 2016}
\end{axis}
\end{tikzpicture}
\end{document}