Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to use legend to name feature to display legend externally. I have two graphs inside a tikz picture which comes from this question.

Here is the code tha to tried to modify and make the legends outside the plot work. However, it gives me a compilation error I do not know the key '/tikz/myplot', which perhaps because I used some style in the legend?

Can someone give me some pointers to resolve this?

\documentclass{article}
\usepackage{mathptmx}
\usepackage{pgf}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{arrows,automata,calc,shapes, positioning,shadows,shadows.blur,shapes.geometric,decorations.pathmorphing,patterns}
\usepackage{color,filecontents}
\begin{document}

\pgfplotsset{major grid style={gray!50}}
\definecolor{step1Col}{HTML}{CC0000}
\definecolor{step2Col}{HTML}{CCCC99}
\definecolor{step3Col}{HTML}{003366}
\definecolor{step4Col}{HTML}{996600}
\definecolor{step5_6Col}{HTML}{669966}
\definecolor{step7Col}{HTML}{666699}
\definecolor{step8Col}{HTML}{FFCC00}
\definecolor{predictedCol}{HTML}{266A2E}

\begin{filecontents*}{plot1.csv}
Number      Step1       Step2       Step3           Step4       Step5_6         Step7           Step8       Predicted
0           50          138         2025137         1400        15859           1358            50          11788769
1           50          894         2088724         1898        14662           2035            50          7564508
2           50          1610        3482495         1405        11490           1302            50          5970268
3           50          871         2089859         898         5021            569             50          7864363
4           50          138         3470704         1405        15888           1302            50          11788769
5           50          871         3481357         1909        11110           1324            50          7560008
6           50          871         2089855         2476        16015           885             50          7878218
7           50          1375        4875299         1903        17401           1258            50          11791029
8           50          877         2786201         1405        10704           1358            50          7871713
9           50          894         2733003         898         5027            569             50          7864363
10          50          138         3481371         1400        15882           1302            50          11788769
11          50          894         2088720         1405        18347           1302            50          7566933
\end{filecontents*}

\begin{center}
\begin{tikzpicture}
\begin{axis}[
myplotShadow/.style={blur shadow={shadow blur radius=0.25pt,shadow yshift=-0.5pt, shadow xshift=0.5pt}},
myplot/.style={draw=none,area legend,draw opacity=0,myplotShadow},
   ybar stacked,
width=10cm,height=5cm,
    bar width=8pt,
    enlarge x limits=0.15,
    ylabel={clock cycles},
   xlabel={tile mapping(VLD, IQ/IDCT, CC)},
  ymajorgrids,
y tick label style={font=\tiny,major tick length=0pt},
x tick label style={font=\tiny,major tick length=0pt},
    xticklabels ={2-1-2, 2-1-3, 2-2-3, 2-2-2, 2-3-2, 2-3-3, 3-3-3, 2-3-3, 2-2-3, 2-2-2, 2-1-2, 2-3-2},
    xtick=data,
   ytick={0,2000000,4000000,6000000,8000000,10000000,12000000},
   xmin=1,
   xmax=10,
   ymin=0,
   ymax=12000000,
axis line style={draw=none},
legend columns=-1,
legend entries={step1,step2, step3, step4, step5+6, step7, step8,predicted},
legend to name=named,
        legend style={draw=none,
       legend cell align=left,
       at={(1.30,1.05)},  },
    ]   

\addplot [myplot,fill=step1Col] table[x=Number,y=Step1] {plot1.csv};
\addplot [myplot,fill=step2Col] table[x=Number,y=Step2] {plot1.csv};
\addplot [myplot,fill=step3Col] table[x=Number,y=Step3] {plot1.csv};
\addplot [myplot,fill=step4Col] table[x=Number,y=Step4] {plot1.csv};
\addplot [myplot,fill=step5_6Col] table[x=Number,y=Step5_6] {plot1.csv};
\addplot [myplot,fill=step7Col] table[x=Number,y=Step7] {plot1.csv};
\addplot [myplot,fill=step8Col,] table[x=Number,y=Step8] {plot1.csv};

%\legend{step1,step2, step3, step4, step5+6, step7, step8}
\end{axis}

\begin{axis}[
width=10cm,
height=5cm,
 xmin=1,
   xmax=10,
   ymin=0,
   ymax=12000000,
    enlarge x limits=0.15,
axis line style={draw=none},
xtick=data,
ytick={},
xticklabels ={},
yticklabels ={},
y tick label style={font=\tiny,major tick length=0pt},
x tick label style={font=\tiny,major tick length=0pt},
ticks=none,
%legend style={draw=none, at={(1.30,0.00)}}
]   

\addplot [only marks, mark=square*,draw opacity=0,    % for the last plot  
fill=predictedCol,legend image post style={xshift=0.25cm}  %for correct legend position
] table[x=Number,y=Predicted] {plot1.csv};
%\legend{predicted}
\end{axis}
\end{tikzpicture}
\\
\ref{named}
\end{center}
\end{document}

Thank You !

share|improve this question
    
Please reduce your code back to a minimal working example (MWE) before posting a question here! That way, you might even come across the problem/solution, and it’ll definitely be easier for other users to answer your question, and to understand the answers given. –  doncherry Apr 27 at 20:45

1 Answer 1

up vote 1 down vote accepted

enter image description here

\documentclass{article}
\usepackage{mathptmx}
\usepackage{pgf}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{arrows,automata,calc,shapes, positioning,shadows,shadows.blur,shapes.geometric,decorations.pathmorphing,patterns}
\usepackage{color,filecontents}
\begin{document}

\pgfplotsset{major grid style={gray!50}}
\definecolor{step1Col}{HTML}{CC0000}
\definecolor{step2Col}{HTML}{CCCC99}
\definecolor{step3Col}{HTML}{003366}
\definecolor{step4Col}{HTML}{996600}
\definecolor{step5_6Col}{HTML}{669966}
\definecolor{step7Col}{HTML}{666699}
\definecolor{step8Col}{HTML}{FFCC00}
\definecolor{predictedCol}{HTML}{266A2E}

\begin{filecontents*}{plot1.csv}
Number      Step1       Step2       Step3           Step4       Step5_6         Step7           Step8       Predicted
0           50          138         2025137         1400        15859           1358            50          11788769
1           50          894         2088724         1898        14662           2035            50          7564508
2           50          1610        3482495         1405        11490           1302            50          5970268
3           50          871         2089859         898         5021            569             50          7864363
4           50          138         3470704         1405        15888           1302            50          11788769
5           50          871         3481357         1909        11110           1324            50          7560008
6           50          871         2089855         2476        16015           885             50          7878218
7           50          1375        4875299         1903        17401           1258            50          11791029
8           50          877         2786201         1405        10704           1358            50          7871713
9           50          894         2733003         898         5027            569             50          7864363
10          50          138         3481371         1400        15882           1302            50          11788769
11          50          894         2088720         1405        18347           1302            50          7566933
\end{filecontents*}

% #### Put this in \pgfplotsset ####
\pgfplotsset{myplotShadow/.style={blur shadow={shadow blur radius=0.25pt,shadow yshift=-0.5pt, shadow xshift=0.5pt}},
myplot/.style={draw=none,area legend,draw opacity=0,myplotShadow}}

\begin{center}
\begin{tikzpicture}
\begin{axis}[
   ybar stacked,
width=10cm,height=5cm,
    bar width=8pt,
    enlarge x limits=0.15,
    ylabel={clock cycles},
   xlabel={tile mapping(VLD, IQ/IDCT, CC)},
  ymajorgrids,
y tick label style={font=\tiny,major tick length=0pt},
x tick label style={font=\tiny,major tick length=0pt},
    xticklabels ={2-1-2, 2-1-3, 2-2-3, 2-2-2, 2-3-2, 2-3-3, 3-3-3, 2-3-3, 2-2-3, 2-2-2, 2-1-2, 2-3-2},
    xtick=data,
   ytick={0,2000000,4000000,6000000,8000000,10000000,12000000},
   xmin=1,
   xmax=10,
   ymin=0,
   ymax=12000000,
axis line style={draw=none},
legend columns=-1,
legend entries={step1,step2, step3, step4, step5+6, step7, step8,predicted},
legend to name=named,
        %legend style={draw=none,
       %legend cell align=left,
       %at={(1.30,1.05)},  },
    ]   

\addplot [myplot,fill=step1Col] table[x=Number,y=Step1] {plot1.csv};
\addplot [myplot,fill=step2Col] table[x=Number,y=Step2] {plot1.csv};
\addplot [myplot,fill=step3Col] table[x=Number,y=Step3] {plot1.csv};
\addplot [myplot,fill=step4Col] table[x=Number,y=Step4] {plot1.csv};
\addplot [myplot,fill=step5_6Col] table[x=Number,y=Step5_6] {plot1.csv};
\addplot [myplot,fill=step7Col] table[x=Number,y=Step7] {plot1.csv};
\addplot [myplot,fill=step8Col,] table[x=Number,y=Step8] {plot1.csv};

%\legend{step1,step2, step3, step4, step5+6, step7, step8}
\end{axis}

\begin{axis}[
width=10cm,
height=5cm,
 xmin=1,
   xmax=10,
   ymin=0,
   ymax=12000000,
    enlarge x limits=0.15,
axis line style={draw=none},
xtick=data,
ytick={},
xticklabels ={},
yticklabels ={},
y tick label style={font=\tiny,major tick length=0pt},
x tick label style={font=\tiny,major tick length=0pt},
ticks=none,
%legend style={draw=none, at={(1.30,0.00)}}
]   

\addplot [only marks, mark=square*,draw opacity=0,    % for the last plot  
fill=predictedCol,legend image post style={xshift=0.25cm}  %for correct legend position
] table[x=Number,y=Predicted] {plot1.csv};
%\legend{predicted}
\end{axis}
\end{tikzpicture}

\ref{named}

\end{center}



\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.