“ominus” 作为 pgfplots 中的 plotmark

“ominus” 作为 pgfplots 中的 plotmark

我有以下散点图:

在此处输入图片描述

我想知道如何使某些点oplus有效,使另一些点ominus无效。

在下面的tex代码中我可以替换:

\addplot[only marks, mark=+, mark size=8pt, thin, color = blue]

和:

\addplot[only marks, mark=oplus, mark size=8pt, thin, color = blue]

哪个有效(我+用进行了更改oplus)并给我以下输出:

在此处输入图片描述

但是,当我想将 更改-为时ominus,却不起作用。

\addplot[only marks, mark=-, mark size=8pt, thin, color = red]

可以工作,但是:

\addplot[only marks, mark=ominus, mark size=8pt, thin, color = red]

才不是。

我曾尝试定义 uni-code:

\usepackage[utf8]{inputenc}
\DeclareUnicodeCharacter{2296}{\anchor} # minus with circle

但无法让它工作。

乳胶:

\documentclass[]{article}

\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{plotmarks}
\usepackage{graphicx}
\usepgfplotslibrary{groupplots}

\definecolor{babyblue}{rgb}{0.54, 0.81, 0.94}
\definecolor{bubblegum}{rgb}{0.99, 0.76, 0.8}

\begin{document}


% plot 1: base plot
\begin{tikzpicture}[scale=0.40]
  \pgfplotsset{
      scale only axis,
  }
  \begin{axis}[
    %xlabel=$A$,
    %ylabel=$B$,
    ticks=none,
  ]

    \addplot[only marks, mark=+, mark size=8pt, thin, color = blue]
    coordinates{ % + data
      (0.05,0.50)
      (0.10,0.15)
      (0.30,0.85)
      (0.45, 0.95)
      (0.60, 0.75)
    }; %\label{plot_one}
    \addplot[only marks, mark=-, mark size=8pt, thin, color = red]
    coordinates{ % + data
      (0.20,0.05)
      (0.25,0.60)
      (0.55,0.40)
      (0.90, 0.85)
      (0.90, 0.15)
    }; 
    
  \end{axis}
\end{tikzpicture}


\end{document}

编辑:

当我应用时,mark = halfcircle当我为背景着色时,我的绘图中会添加一些空白。我怎样才能将它们着色为与背景相同的颜色?

在此处输入图片描述

新文本:

\documentclass[]{article}

\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{plotmarks}
\usepackage{graphicx}
\usepgfplotslibrary{groupplots}

\definecolor{babyblue}{rgb}{0.54, 0.81, 0.94}
\definecolor{bubblegum}{rgb}{0.99, 0.76, 0.8}

\begin{document}


% plot 1: base plot
\begin{tikzpicture}[scale=0.40]
  \pgfplotsset{
      scale only axis,
  }
  \begin{axis}[
    %xlabel=$A$,
    %ylabel=$B$,
    ticks=none,
  ]

    \addplot[only marks, mark=+, mark size=8pt, thin, color = blue]
    coordinates{ % + data
      (0.05,0.50)
      (0.10,0.15)
      (0.30,0.85)
      (0.45, 0.95)
      (0.60, 0.75)
    }; %\label{plot_one}
    \addplot[only marks, mark=halfcircle, mark size=8pt, thin, color = red]
    coordinates{ % + data
      (0.20,0.05)
      (0.25,0.60)
      (0.55,0.40)
      (0.90, 0.85)
      (0.90, 0.15)
    }; 
    
        \path[name path = begin_left_shade_path_4] (axis cs:1.0, 0.7) -- (axis cs:0.0, 0.7);
    \path[name path = end_left_shade_path_4] (axis cs:1.0, 0.0) -- (axis cs:0.0, 0.0);
    \addplot [bubblegum] fill between[of = begin_left_shade_path_4 and end_left_shade_path_4, soft clip = {domain=0.0:0.95}];
    
    \path[name path = begin_left_shade_path_2] (axis cs:0.0, 1.0) -- (axis cs:1.0, 1.0);
    \path[name path = end_left_shade_path_2] (axis cs:0.0, 0.70) -- (axis cs:1.0, 0.70);
    \addplot [babyblue] fill between[of = begin_left_shade_path_2 and end_left_shade_path_2, soft clip = {domain=0.0:0.95}];
    
  \end{axis}
\end{tikzpicture}


\end{document}

答案1

如果您阅读了 PGFPlots 手册中有关标记的内容,您将不会发现这个不祥的ominus标记。对于halfcircle第 184 页:

标记=半圆

其中一半用白色填充(更准确地说,用标记颜色)。

因此您只需将其更改mark color为与背景相同即可:

\documentclass[]{article}

\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{plotmarks}
\usepackage{graphicx}
\usepgfplotslibrary{groupplots}

\definecolor{babyblue}{rgb}{0.54, 0.81, 0.94}
\definecolor{bubblegum}{rgb}{0.99, 0.76, 0.8}

\begin{document}
% plot 1: base plot
\begin{tikzpicture}[scale=0.40]
  \pgfplotsset{
      scale only axis,
  }
  \begin{axis}[
    %xlabel=$A$,
    %ylabel=$B$,
    ticks=none,
  ]

    \addplot[only marks, mark=+, mark size=8pt, thin, color = blue]
    coordinates{ % + data
      (0.05,0.50)
      (0.10,0.15)
      (0.30,0.85)
      (0.45, 0.95)
      (0.60, 0.75)
    }; %\label{plot_one}
    \addplot[only marks, mark=halfcircle, mark color=bubblegum, mark size=8pt, thin, color = red]
    coordinates{ % + data
      (0.20,0.05)
      (0.25,0.60)
      (0.55,0.40)
      (0.90, 0.15)
    }; 
    \addplot[only marks, mark=halfcircle, mark color=babyblue, mark size=8pt, thin, color = red]
    coordinates{ % + data
      (0.90, 0.85)
    }; 
 
     \path[name path = begin_left_shade_path_4] (axis cs:1.0, 0.7) -- (axis cs:0.0, 0.7);
    \path[name path = end_left_shade_path_4] (axis cs:1.0, 0.0) -- (axis cs:0.0, 0.0);
    \addplot [bubblegum] fill between[of = begin_left_shade_path_4 and end_left_shade_path_4, soft clip = {domain=0.0:0.95}];
    
    \path[name path = begin_left_shade_path_2] (axis cs:0.0, 1.0) -- (axis cs:1.0, 1.0);
    \path[name path = end_left_shade_path_2] (axis cs:0.0, 0.70) -- (axis cs:1.0, 0.70);
    \addplot [babyblue] fill between[of = begin_left_shade_path_2 and end_left_shade_path_2, soft clip = {domain=0.0:0.95}];
    
  \end{axis}
\end{tikzpicture}
\end{document}

带加号/减号的绘图

编辑: 在 TikZ 手册中,我发现了这一点:

特殊值 none 禁止填充相应部分。

因此你可以使用:

\addplot[only marks, mark=halfcircle, mark color=none, mark size=8pt, thin, color = red]

答案2

由于没有“ominus-mark”,您可以自己创建标记:

\pgfdeclareplotmark{myominus}{....}

1a. 新的。如果您想使用现成的东西,您可以circle splitshapes图书馆中获取。

请注意,另一种可能性是mark=halfcircle,由于“一半用白色填充”,因此并不适合可填充的“预兆”

\pgfdeclareplotmark{myominus}{
\node[shape=circle split, 
draw,   fill,    minimum size=2*\pgfplotmarksize, inner sep=0pt,
]{};
}

在此处输入图片描述

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest} 
\usetikzlibrary{shapes}% <---

\pgfdeclareplotmark{myominus}{
\node[shape=circle split, 
draw,   fill,  
minimum size=2*\pgfplotmarksize, inner sep=0pt,
]{};
}

\begin{document}
\begin{tikzpicture}
\begin{axis}[ 
only marks, 
mark size=5pt 
]
\addplot+[mark=oplus*, mark options={fill=cyan!55}] coordinates { 
     (0.20,0.05) %
      (0.25,0.60)
      (0.55,0.40)
      (0.90, 0.85)  
};
\addplot+[red, mark=myominus, mark options={fill=pink} ] coordinates { 
     (0.20,0.05) % 
      (0.05,0.50)
      (0.10,0.15)
      (0.30,0.85)
      (0.45, 0.95)
      (0.60, 0.75)
};
\end{axis}
\end{tikzpicture}
\end{document}

1b.因为您在处理时改变了您的问题,所以我确实不知道您想要创建什么。

在此处输入图片描述

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest} 
\usetikzlibrary{shapes}% <---

\pgfdeclareplotmark{myominus}{
\node[shape=circle split, 
draw,  minimum size=2*\pgfplotmarksize, inner sep=0pt,
]{};
}
\pgfdeclareplotmark{myominus*}{
\node[shape=circle split, 
draw,   fill,  
minimum size=2*\pgfplotmarksize, inner sep=0pt,
]{};
}

\begin{document}
\begin{tikzpicture}
\begin{axis}[ 
ticks=none,    
only marks, 
mark size=5.67pt
]
\addplot+[mark=oplus, mark options={fill=none}] coordinates { 
     (0.20,0.05) %
      (0.25,0.60)
      (0.55,0.40)
      (0.90, 0.85)  
};

\addplot+[mark=oplus*, draw=brown, mark options={draw=brown, fill=purple!44}] coordinates { 
      (0.35,0.60)
};

\addplot+[red, mark=myominus] coordinates { 
      (0.05,0.50)
%      (0.10,0.15)
      (0.30,0.85)
      (0.45, 0.95)
      (0.60, 0.75)
};

\addplot+[mark=myominus*,  draw=green, mark options={fill=yellow}] coordinates { 
      (0.10,0.15)
}; 
      
\fill[pink] (0,0) rectangle (0.95, 0.6);
\fill[cyan!55] (0,0.6) rectangle (0.95, 1.0);
\end{axis}
\end{tikzpicture}
\end{document}

2. 旧的。

\pgfdeclareplotmark{myominus}{
\node[inner sep=-1.4pt, circle, draw, fill=pink] {$-$};
}

在此处输入图片描述

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest} 

\tikzset{
markstyle/.style={inner sep=-1.4pt, circle, draw,   },
}
\pgfdeclareplotmark{myominus}{
\node[markstyle, fill=pink] {$-$};
}
\pgfdeclareplotmark{myoplus}{
\node[markstyle, fill=cyan!55]{$+$};
}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
only marks, 
]
\addplot+[mark=myominus] coordinates { 
     (0.20,0.05)
      (0.25,0.60)
      (0.55,0.40)
      (0.90, 0.85)  
};
\addplot+[mark=myoplus] coordinates { 
      (0.05,0.50)
      (0.10,0.15)
      (0.30,0.85)
      (0.45, 0.95)
      (0.60, 0.75)
};
\end{axis}
\end{tikzpicture}
\end{document}

相关内容