3

I have been using the tikz package to plot my graphs. When I want to describe each graph in a plot, I use "legend entries" and using "legend pos" I can manage the box describing the graphs. But now I want to have some legend entries in a different position as it can be seen in the figure that I have attached it. Here is a code that I want to make a change in it.

\documentclass[12 pt]{article} 
\usepackage{times,bm}
\usepackage[affil-it,]{authblk}
\usepackage[colorlinks,linkcolor=blue,citecolor=blue]{hyperref}
\usepackage[margin=1 in]{geometry}
\geometry{landscape,a4paper} 
\usepackage{graphicx,fancyref}
\usepackage{cite}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{float}
\usepackage{multirow,multicol}
\usepackage{tabulary}
\usepackage[flushleft]{threeparttable}
\usepackage{pgfplots,subfigure}
\usepackage[dvipsnames]{xcolor}
\numberwithin{equation}{section}
\usepackage{tikz}
\usepgflibrary{arrows}
\usetikzlibrary{shapes.callouts}
\tikzset{  
    level/.style   = { thick, },
    connect/.style = { dotted, red   },
    notice/.style  = { draw, rectangle callout, callout relative pointer=        {#1} },
    label/.style   = { text width=2cm }}

\begin{document}

\begin{figure}
    \centering
\begin{tikzpicture}[scale=2, ]
    \begin{axis}[ 
        xlabel={$\varepsilon$},
        ylabel={$E$},
        legend entries={$1/2[400]$,$1/2[411]$,$3/2[402]$,$1/2[420]$,$3/2[411]$,$5/2[402]$,$1/2[431]$,$3/2[422]$,$5/2[413]$,$7/2[404]$,$1/2[440]$,$3/2[431]$,$5/2[422]$,$7/2[413]$,$9/2[404]$,},
        legend pos=outer north east,legend columns=2 ]
        \addplot [thick, Apricot]       table {sdg1.dat};
        \addplot [thick, Aquamarine]    table {sdg2.dat};
        \addplot [thick, BurntOrange]   table {sdg3.dat};
        \addplot [thick, black]         table {sdg4.dat};
        \addplot [thick, blue]          table {sdg5.dat};
        \addplot [thick, BlueGreen]     table {sdg6.dat};
        \addplot [thick, CadetBlue]     table {sdg7.dat};
        \addplot [thick, DarkOrchid]    table {sdg8.dat};
        \addplot [thick, Brown]         table {sdg9.dat};
        \addplot [thick, ForestGreen]   table {sdg10.dat};
        \addplot [thick, Goldenrod]     table {sdg11.dat};
        \addplot [thick, Green]         table {sdg12.dat};
        \addplot [thick, cyan]          table {sdg13.dat};
        \addplot [thick, JungleGreen]   table {sdg14.dat};
        \addplot [thick, gray]          table {sdg15.dat};
    \end{axis}
\end{tikzpicture}
\end{figure}


   \end{document}

This code gives me enter image description here

But I want to have

How can I figure it out? enter image description here

You can acces to data file clicking the here.

Thanks.

  • add node at end of \addplot code line. for more, provide mwe (minimal working example) which generate showed image. – Zarko May 14 '18 at 6:40
  • I have added my code dear Zarko. – HS8637 May 14 '18 at 7:03
8

like this:

enter image description here

since i haven't your tables with plotting data, i simulate only three of them with coordinates. this should be sufficient to see a way, how labels are added to your curves in diagram.

\documentclass[12 pt]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

\begin{document}
    \begin{figure}
    \centering
\begin{tikzpicture}[scale=2]
    \begin{axis}[
        width=70mm,             % new
        xlabel={$\varepsilon$},
        ylabel={$E$},
        ymin=0, ymax=6,         % new, needed for my coordinates, can be omitted
        axis y line=left,       % new
        y axis line style={-},  % new
        % no marks,             % use in the case if you not like to have marks on curves
        clip=false,             % new
        font=\footnotesize      % new, but is not important
                ]
        \addplot +[thick]   coordinates {(0,3) (2,5)} node[right] {$1/2[400]$};
        \addplot +[thick]   coordinates {(0,2) (2,4)} node[right] {$1/2[411]$};
        \addplot +[thick]   coordinates {(0,1) (2,3)} node[right] {$3/2[402]$};
    \end{axis}
\end{tikzpicture}
    \end{figure}
\end{document}
  • 3
    Congratulations for your 100K! – egreg May 14 '18 at 8:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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