我希望图例与图表中的线图相匹配。我参考了很多图例问题,但我找不到一个试图为单个外部图形文件制作多个图例的问题。如果能得到一些帮助,我将不胜感激。这是带有附加图像文件的 MWE。
\documentclass{article}
\usepackage{graphicx}
\usepackage{epstopdf}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{loglogaxis} [
width=\textwidth,
enlargelimits = false,
xmin = 0.0078,
xmax = 32,
ymin = 0.78e-8,
ymax=109008.9,
max space between ticks = 60,
axis on top,
xlabel = Frequency (Hz),
ylabel = Power spectral density (dB),
]
\addplot graphics [
xmin = 0.0078,
xmax = 32,
ymin = 0.78e-8,
ymax=109008.9,
]
{psd_WsBlroot1.png};
\addlegendimage{draw=black,mark=none, line width=3pt, color=black},
\addlegendentry{Lidar wind speed 50m},
\addlegendimage{line width=3pt, color=gray},
\addlegendentry{Blade1 root bending moment},
\end{loglogaxis}
\end{tikzpicture}
\end{document}
答案1
您只需要在添加默认线条定义之前创建图例即可\addplot
。(我在复制图形文件时重命名了它。对此我很抱歉。)
\documentclass{article}
\usepackage{graphicx}
\usepackage{epstopdf}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{loglogaxis} [
width=\textwidth,
enlargelimits = false,
xmin = 0.0078,
xmax = 32,
ymin = 0.78e-8,
ymax=109008.9,
max space between ticks = 60,
axis on top,
xlabel = Frequency (Hz),
ylabel = Power spectral density (dB),
]
\addlegendimage{draw=black,mark=none, line width=3pt, color=black},
\addlegendentry{Lidar wind speed 50m},
\addlegendimage{line width=3pt, color=gray},
\addlegendentry{Blade1 root bending moment},
\addplot graphics [
xmin = 0.0078,
xmax = 32,
ymin = 0.78e-8,
ymax=109008.9,
]
{images/graph.png};
\end{loglogaxis}
\end{tikzpicture}
\end{document}