3

I'm trying to create a plot that is using color as the third dimension. However, I want to create the "axis" of that third dimension exponentially, as most values are quite close to 0. My problem is that I can not use the exponential function I created in \addlegend

Any help is highly welcome :)

Here is a working code:

\documentclass{minimal}

% for checkmarks and crosses \usepackage{amsmath} \usepackage{acronym}

% for confidence interval plot \usepackage{tikz} \usepackage{rotating} \usepackage{verbatim} \usepackage{pgfplots}

\pgfplotsset{compat=1.17} \definecolorseries{plotcolor}{rgb}{last}{blue!0}{blue!100} \resetcolorseries[100]{plotcolor} \pgfplotsset{ my area legend/.style={ draw=none, inner ysep=0pt, inner xsep=3pt, row sep=-.5\pgflinewidth, nodes={inner ysep=0pt}, legend image code/.code={% \filldraw[#1,draw=none] (0cm,-0.08cm) rectangle (0.4cm,0.08cm); } }, myplotcolor/.style={plotcolor!![#1]} }

\begin{document} %\begin{sidewaysfigure} %\pgfsetplotmarksize{0pt} \begin{tikzpicture}[scale=1.0, declare function={ scale = 0.03782885669; % colorcalc(\nofront) = e^(\nofront * scale) - 1; colorcalc(\nofront) = \nofront; }], \centering \begin{axis}[ legend style={ at={(1,0)},yshift=350pt,xshift=1em,anchor=north east, my area legend, name=legend }, height=15cm, width=\textwidth,
ymax=3300, ymin=0, xmin=0.5, xmax=21.5, ymajorgrids=true, axis y line=left, axis x line=bottom, xtick={1,...,21}, x tick label style={rotate=90,anchor=east}]

            \foreach \x/\mean/\nofront [evaluate=\nofront as \color using {colorcalc(\nofront)}] in {1/0/0, 2/2414/27, 3/2475/61, 4/887/7, 5/753/1, 6/726/1, 7/1011/12, 8/499/2, 9/646/6, 10/546/4, 11/2498/77, 12/708/13, 13/753/9, 14/0/0, 15/2670/97, 16/0/0, 17/1065/12, 18/627/17, 19/353/0, 20/0/0, 21/741/12} {
                \edef\temp{\noexpand\addplot[ybar,blue,forget plot,fill=blue!\color] coordinates {(\x,\mean)};
                }
                \temp
            }

            \addplot+[only marks,blue,mark options={draw=blue,fill=blue},forget plot][error bars/.cd,y dir=both, y explicit]
            coordinates {
            (1,0) +- (0,0)
            (2,2414) +- (0,590)
            (3,2475) +- (0,789)
            (4,887) +- (0,262)
            (5,753) +- (0,105)
            (6,726) +- (0,105)
            (7,1011) +- (0,64)
            (8,499) +- (0,43)
            (9,646) +- (0,93)
            (10,546) +- (0,136)
            (11,2498) +- (0,393)
            (12,708) +- (0,102)
            (13,753) +- (0,145)
            (14,0) +- (0,0)
            (15,2670) +- (0,484)
            (16,0) +- (0,0)
            (17,1065) +- (0,65)
            (18,627) +- (0,287)
            (19,353) +- (0,0)
            (20,0) +- (0,0)
            (21,741) +- (0,80)
            };

            \pgfplotsinvokeforeach {100,95,...,5}{
                \addlegendimage{myplotcolor=#1,my area legend}
                \addlegendentry{}
            }
            % what I would actually want:
            % \pgfplotsinvokeforeach {100,95,...,5}{
            %     \addlegendimage{myplotcolor=colorcalc(#1),my area legend}
            %     \addlegendentry{}
            % }

            % other things I've tried:
            % \addlegendimage{myplotcolor=colorcalc(100),my area legend}
            % \addlegendentry{}
            % \addlegendimage{myplotcolor=colorcalc(0),my area legend}
            % \addlegendentry{}

            % \pgfplotsinvokeforeach {100,95,...,5,0}{
            %     \edef\temp{
            %     \noexpand\addlegendimage{myplotcolor=colorcalc(#1),my area legend}
            %     }\temp;
            %     \addlegendentry{}
            % }

            % \pgfplotsinvokeforeach {100,95,...,5,0}{
            %     \pgfmathsetmacro{\colorme}{colorcalc(#1)}
            %     \addlegendimage{blue!\colorme,my area legend}
            %     \addlegendentry{}
            % }

            % \foreach \nofront [evaluate=\nofront as \colortwo using {colorcalc(\nofront)}] in {100,95,...,5,0}{
            %     \addlegendimage{myplotcolor=\colortwo,my area legend}
            %     \addlegendentry{}
            % }

            % \pgfplotsinvokeforeach {100,95,...,5,0}{
            %     \edef\temp{myplotcolor=colorcalc(#1),my area legend}
            %     \expandafter\addlegendimage\temp;
            %     \addlegendentry{}
            % }
        \end{axis}
        % % Beschriftung der Legende
        %   \path[nodes={font=\tiny,inner xsep=0pt}]
        %     (legend.north west) node [anchor= east] {$122$}
        %     (legend.west) node [anchor= east] {$61$}
        %     (legend.south west) node [anchor= east] {$0$}
        %     (legend.north) node [anchor=south] {$\varnothing \in 122$}
        %   ;
   \end{tikzpicture}%     

\end{document}

0 Answers0