为多个图添加全局图例

为多个图添加全局图例

我正在尝试为条形图创建全局图例。我目前的尝试如下所示,有没有办法将颜色更改为图中的相应颜色,并将符号更改为全局图例中的条形图符号?

另外,我怎样才能将标题置于每个图的中央?目前,似乎我的所有标题都向左对齐

这是我的 LaTeX 代码:

\begin{figure}[H]
\begin{minipage}{0.49\textwidth}
    \resizebox{\textwidth}{!}{%
    \begin{tikzpicture}[baseline]
        \begin{axis}[
        ybar,
        bar width=0.1cm,
        width= 7.4cm,
        xtick=data,
        symbolic x coords = {Base, Random, Unequal, Imbalanced}
        ]

        \addplot+[bar shift=0cm, forget plot] coordinates {(Base, 0.702)};
        \addplot coordinates {(Random, 0.677) (Unequal, 0.699) (Imbalanced, 0.687)};
        \addplot coordinates {(Random, 0.684) (Unequal, 0.665) (Imbalanced, 0.64)};
        \addplot coordinates {(Random, 0.679) (Unequal, 0.67) (Imbalanced, 0.611)};
        \addplot coordinates {(Random, 0.691) (Unequal, 0.69) (Imbalanced, 0.672)};
        \addplot coordinates {(Random, 0.706) (Unequal, 0.706) (Imbalanced, 0.703)};

        \end{axis}
    \end{tikzpicture}
    }
    \caption{Heart Failure F1-Scores}\label{fig7}
\end{minipage}%
\begin{minipage}{0.49\textwidth}
    \resizebox{\textwidth}{!}{%
    \begin{tikzpicture}[baseline] 
        \begin{axis}[
        ybar,
        bar width=0.1cm,
        width=7.4cm,
        xtick=data,
        symbolic x coords = {Base, Random, Unequal, Imbalanced}
        ]

        \addplot+[bar shift=0cm, forget plot] coordinates {(Base, 0.922)};
        \addplot coordinates {(Random, 0.891) (Unequal, 0.902) (Imbalanced, 0.893)};
        \addplot coordinates {(Random, 0.895) (Unequal, 0.888) (Imbalanced, 0.885)};
        \addplot coordinates {(Random, 0.893) (Unequal, 0.877) (Imbalanced, 0.883)};
        \addplot coordinates {(Random, 0.921) (Unequal, 0.915) (Imbalanced, 0.914)};
        \addplot coordinates {(Random, 0.922) (Unequal, 0.918) (Imbalanced, 0.919)};

        \end{axis}
    \end{tikzpicture}
    }
    \caption{Heart Failure AUC-ROC}\label{fig8}
\end{minipage}%

\begin{tikzpicture}
    \begin{axis}[
        legend columns=5,
        legend style={%
        at={(-100,-100)},%
        anchor=north east,%
        at={(axis description cs:1,10),%
        },%
    /tikz/column 2/.style={column sep=5pt,},},]
    \addplot {0}; 
    \addlegendentry{Local 1}
    \addplot {0};
    \addlegendentry{Local 2}
    \addplot {0};
    \addlegendentry{Local 3}
    \addplot {0};
    \addlegendentry{Random Merge}
    \addplot {0};
    \addlegendentry{Weighted Merge}
    \end{axis}
\end{tikzpicture}
\end{figure}

相关内容