.png)
분산형 차트에 대한 마커의 모양+색상을 사용자 정의하려고 합니다. Everythink는 색상(예: 빨간색)을 하드 코딩하면 작동합니다.
\documentclass{article}
\usepackage{pgfplots}
\usepackage{xcolor}
\newcommand{\myStyle}{%
% define marker shape here
\tikzset{marker/.style={circle, inner sep=1.5pt, fill=red}}
}
\pgfdeclareplotmark{mymarker}{%
\node[marker] {};
}
\begin{document}
\begin{tikzpicture}
\myStyle
\begin{axis}[]
\addplot[only marks, mark=mymarker, smooth] coordinates {
(3, 0.5)
(4, 0.6)
(5, 0.4)
};
\end{axis}
\end{tikzpicture}
하지만 각 플롯마다 개별적으로 색상을 만드는 데 어려움을 겪고 있습니다. 나는 정의할 수 있다
\newcommand{\myStyle}[1]{%
% define marker shape here
\tikzset{marker/.style={circle, inner sep=1.5pt, fill=#1}}
}
하지만 블록 내부의 색상을 지정해야 할 것 같아요
\pgfdeclareplotmark{mymarker}{%
\node[marker] {};
}
각 addplot 명령의 색상을 변경합니다. 그러나 색상을 \pgfdeclareplotmark 명령의 인수로 전달하는 방법을 잘 모르겠습니다.
답변1
편집 1
\documentclass{article}
\usepackage{pgfplots}
\usepackage{xcolor}
\pgfplotsset{compat=1.17} % Ensure compatibility with pgfplots
% Declare macro to create customized markers with a specific color
\newcommand{\declareCustomMarker}[2]{%
\pgfdeclareplotmark{#1}{%
\node[circle, inner sep=1.5pt, fill=#2] {};
}
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[]
% Declare markers with different colors
\declareCustomMarker{mymarker-blue}{blue}
\declareCustomMarker{mymarker-green}{green}
% Use the blue marker for this plot
\addplot[only marks, mark=mymarker-blue, smooth] coordinates {
(3, 0.5)
(4, 0.6)
(5, 0.4)
};
% Use the green marker for this plot
\addplot[only marks, mark=mymarker-green, smooth] coordinates {
(2, 0.7)
(4, 0.8)
(6, 0.9)
};
\end{axis}
\end{tikzpicture}
\end{document}
이와 같이 ?
\documentclass{article}
\usepackage{pgfplots}
\usepackage{xcolor}
\pgfkeys{/tikz/.cd,
marker color/.store in=\markercolor,
marker color=red % default color
}
\newcommand{\myStyle}[1]{%
\pgfkeys{/tikz/marker color=#1} % set the marker color
% define marker shape here
\tikzset{marker/.style={circle, inner sep=1.5pt, fill=\markercolor}}
}
\pgfdeclareplotmark{mymarker}{%
\node[marker] {};
}
\begin{document}
\begin{tikzpicture}
\myStyle{red} % <= marker color here
\begin{axis}[]
\addplot[only marks, mark=mymarker, smooth] coordinates {
(3, 0.5)
(4, 0.6)
(5, 0.4)
};
\end{axis}
\end{tikzpicture}
\end{document}