我想通过使用命令改变参数来绘制多条曲线\foreach
。从那方面来说,没问题。我无法做的是为每条曲线分配不同的颜色,最终是我之前设置的颜色。
我的 WME :
\documentclass{article}
\usepackage{pstricks-add}
\usepackage{pst-plot}
\usepackage{siunitx}
\usepackage{pgfplots}
\usepackage{pgf-spectra}
\usepgfplotslibrary{fillbetween}
% Preamble:
\pgfplotsset{width=10cm,compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[title=Loi de Wien, xlabel={Longueur d'onde ($\unit{\um}$)},%
ylabel={Luminance énergétique \\ ($\unit{\watt \per \square \metre \per \steradian}$)},%
ylabel style = {align=center}, domain=0:2.5, ymax=80]%
\foreach \p in {3000,4000,5000, 6000, 7000} {
\addplot [blue, samples=200]{119.268/(x^5*(exp(14404/(x*\p))-1))};
\addlegendentryexpanded{T=$\p \unit{\kelvin}$}
}
\end{axis}
\end{tikzpicture}
\end{document}
谢谢
答案1
这对你有帮助吗?
\documentclass{article}
\usepackage{pstricks-add}
\usepackage{pst-plot}
\usepackage{siunitx}
\usepackage{pgfplots}
\usepackage{pgf-spectra}
\usepgfplotslibrary{fillbetween}
% Preamble:
\pgfplotsset{width=10cm,compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[title=Loi de Wien, xlabel={Longueur d'onde ($\unit{\um}$)},%
ylabel={Luminance énergétique \\ ($\unit{\watt \per \square \metre \per \steradian}$)},%
ylabel style = {align=center}, domain=0:2.5, ymax=80]%
\foreach \p/\i in {3000/yellow, 4000/blue, 5000/orange, 6000/green, 7000/red}{
\edef\temp{\noexpand\addplot [\i, samples=200]{119.268/(x^5*(exp(14404/(x*\p))-1))};}
\addlegendentryexpanded{T=$\p \unit{\kelvin}$}
\temp
}
\end{axis}
\end{tikzpicture}
\end{document}