0

I need to create a detailed scatter plot. It contains two different plots, each with several classes - each plots can contain upward of 1000 coordinates with varying levels/classes in each. There may also be more than 2 plots.

After lots of searching I got the colors and classes right, but now I would like to split the legend into one for the classes, and one representing each plot.

I am only getting one of two scenarios:

Either I can have eq. \addlegendentry{A} after my plot,which then shows A and B in a legend - but does not specify the marker type (figure 1).

enter image description here

Or if I comment out and only specify the class legend entries, I get the correct legend with the different class colors (figure 2).

enter image description here

What would like to see is both legends, seperately, but with the A/B legend in black and showing the marker style. Something in the line of the following:

enter image description here

I am aware that I could modify the classes to A1 ... A10, B1 ... B10, but this would result in a long list of legend entries. I would prefer it to keep it simplified.

Any help will be tremendously appreciated!

MWE:

\documentclass{article}
\usepackage[a4paper, left=1.5cm, right= 1.5cm, top=1.5cm, bottom = 1.5cm]{geometry}
\usepackage{pdflscape}
\usepackage{pgfplots}
\pgfplotsset{compat = 1.3}
\usepackage{tikz}
\usetikzlibrary{pgfplots.dateplot,calc,plotmarks}

\definecolor{grey2}{RGB}{100, 100, 100}
\definecolor{blue1}{RGB}{99, 190, 255}
\definecolor{blue2}{RGB}{0, 128, 192}
\definecolor{blue3}{RGB}{82, 15, 191}
\definecolor{green1}{RGB}{135, 255, 66}
\definecolor{green2}{RGB}{42, 173, 40}
\definecolor{yellow1}{RGB}{255, 245, 66}
\definecolor{orange1}{RGB}{255, 160, 66}
\definecolor{pink1}{RGB}{255, 99, 174}
\definecolor{purple1}{RGB}{187, 99, 255}
\definecolor{red2}{RGB}{255, 66, 66}

%-------------------------
\begin{document}
\begin{landscape}
\begin{center}
\begin{tikzpicture}
    \begin{axis}
        [width = 10cm, height = 10cm, 
    scatter,
        only marks,
        scatter src=explicit symbolic,
            scatter/classes={           
                1={grey2},
                2={blue1},
                3={green1},
                4={green2},
                5={yellow1},
                6={orange1},
                7={red2},
                8={purple1},
                9={pink1},
                10={black}
            },
            legend style={
            at={(0.5,-0.135)},
                anchor=north,
                inner sep = 0.2cm,
            },
            legend columns=10,
            legend entries={1,2,3,4,5,6,7,8,9,10},
            tick pos = left,
            ymin = -0.1,
        ]
        \addplot [mark size=2.5pt, mark=*] coordinates { (5.8, 5.7) [4] (4, 5.4) [4] (4, 5.6) [3] (4.2, 5.5) [3] (3.9, 5.4) [2] (2.1, 2.6) [1] (2.4, 2.6) [1] (2.3, 7.3) [5] (2.4, 7.3) [5] (5.5, 7.2) [6] (6, 10.1) [8] (7.3, 10) [8] (10, 9.2) [7] (3.8, 9.3) [7] }; 
                 %\addlegendentry{A} %when this is commented out, I get only the classes
        \addplot [mark size = 3pt, mark=square] coordinates { (2.4, 5.7) [4] (3.6, 5.5) [3] (3.5, 4.1) [2] (8.7, 3.5) [2] (6.0, 2.7) [1] (5.2, 8.3) [6] };
                 %\addlegendentry{B}  %when this is commented out, I get only the classes
\end{axis}
\end{tikzpicture}
\end{center}
\end{landscape}
\end{document}

0 Answers0