# Revision history [back]

### Legend attached to curve in plot ("PlotLabels")

Hello,

I have a plot with several curves (say, 5) and I need to clearly mark them (can't yet upload an example, sorry).

The plot should be grayscale friendly (I am giving curves different shades, but it is not enough), and line style (dotted...) already has a different meaning. I am using a legend, but it goes in a separate box and does not really help a lot.

Since the different curves never cross in a given plot, just attaching the legend label to the curve tail would be great: how can I achieve this? To be clear, I am looking for an equivalent of Mathematica PlotLabels.

### Legend attached to curve in plot ("PlotLabels")

Hello,

I have a plot with several curves (say, 5) and I need to clearly mark them (can't yet upload an example, sorry).them.

The plot should be grayscale friendly (I am giving curves different shades, but it is not enough), and line style (dotted...) already has a different meaning. I am using a legend, but it goes in a separate box and does not really help a lot.

Since the different curves never cross in a given plot, just attaching the legend label to the curve tail would be great: how can I achieve this? To be clear, I am looking for an equivalent of Mathematica PlotLabels.

The following example gives an idea of the 'most overlapping' case I can be interested in (actually an exaggeration, a real plot would stop at nexp=2.5):

f(x,n) = e^(-1/(n*x))
listexp = srange(0.5, 3+0.1, 0.5)
lenght = float(len(listexp))
xMinPlot = 0.1

p = Graphics()
for i,nexp in enumerate(listexp) :
c = 10^nexp
p += plot_semilogx(f(x,c), (x, xMinPlot, 10), hue=i/lenght)

p.show()


Using slelievre answer (and imitating the PlotLabels idea, putting gray lines between plot and label), I came up with this:

text_options = {...}
offsets = [0.01, 0.01, 0.01, -0.02, -0.02, 0.02]
xlabel = xMinPlot*0.85
xline  = xMinPlot*0.97

for i,nexp in enumerate(listexp) :
c = 10^nexp
yline = f(xMinPlot,c)
p += line(((xline,yline),(xlabel,yline+offsets[i])), color='gray', thickness=0.5)
p += text('$c = 10^{{ {:.1f} }}$'.format(float(nexp)),
(xlabel, yline+offsets[i]), **text_options)

p.show(xmin=5*10^-2, xmax=10)


This approach requires to analyse each plot case by case and playing around to find a solution, but I am afraid there is nothing one can do to partially automate it. Also, I am not sure that I am doing this the best way, or whether the result could look better/more professional.

### Legend attached to curve in plot ("PlotLabels")

Hello,

I have a plot with several curves (say, 5) and I need to clearly mark them.

The plot should be grayscale friendly (I am giving curves different shades, but it is not enough), and line style (dotted...) already has a different meaning. I am using a legend, but it goes in a separate box and does not really help a lot.

Since the different curves never cross in a given plot, just attaching the legend label to the curve tail would be great: how can I achieve this? To be clear, I am looking for an equivalent of Mathematica PlotLabels.

The following example gives an idea of the 'most overlapping' case I can be interested in (actually an exaggeration, a real plot would stop at nexp=2.5):

sage: f(x,n) = e^(-1/(n*x))
....: listexp = srange(0.5, 3+0.1, 0.5)
....: lenght = float(len(listexp))
....: xMinPlot = 0.1
....:
....: p = Graphics()
....: for i,nexp in enumerate(listexp) :
....:     c = 10^nexp
....:     p += plot_semilogx(f(x,c), (x, xMinPlot, 10), hue=i/lenght)

p.show()

....: ....: p.show()

Using slelievre answer (and imitating the PlotLabels idea, putting gray lines between plot and label), I came up with this:

text_options = {...}
offsets = [0.01, 0.01, 0.01, -0.02, -0.02, 0.02]
xlabel = xMinPlot*0.85
xline  = xMinPlot*0.97

for i,nexp in enumerate(listexp) :
c = 10^nexp
yline = f(xMinPlot,c)
p += line(((xline,yline),(xlabel,yline+offsets[i])), color='gray', thickness=0.5)
p += text('$c = 10^{{ {:.1f} }}$'.format(float(nexp)),
(xlabel, yline+offsets[i]), **text_options)

p.show(xmin=5*10^-2, xmax=10)


a b This approach requires to analyse each plot case by case and playing around to find a solution, but I am afraid there is nothing one can do to partially automate it. Also, I am not sure that I am doing this the best way, or whether the result could look better/more professional.professional. a

### Legend attached to curve in plot ("PlotLabels")

Hello,

I have a plot with several curves (say, 5) and I need to clearly mark them.

The plot should be grayscale friendly (I am giving curves different shades, but it is not enough), and line style (dotted...) already has a different meaning. I am using a legend, but it goes in a separate box and does not really help a lot.

Since the different curves never cross in a given plot, just attaching the legend label to the curve tail would be great: how can I achieve this? To be clear, I am looking for an equivalent of Mathematica PlotLabels.

The following example gives an idea of the 'most overlapping' case I can be interested in (actually an exaggeration, a real plot would stop at nexp=2.5):

sage:

f(x,n) = e^(-1/(n*x))
....: listexp = srange(0.5, 3+0.1, 0.5)
....: lenght = float(len(listexp))
....: xMinPlot = 0.1
....:
....:  p = Graphics()
....: for i,nexp in enumerate(listexp) :
....:     c = 10^nexp
....:     p += plot_semilogx(f(x,c), (x, xMinPlot, 10), hue=i/lenght)
....:
....: p.show()
p.show()


Using slelievre answer (and imitating the PlotLabels idea, putting gray lines between plot and label), I came up with this:

text_options = {...}
offsets = [0.01, 0.01, 0.01, -0.02, -0.02, 0.02]
xlabel = xMinPlot*0.85
xline  = xMinPlot*0.97

for i,nexp in enumerate(listexp) :
c = 10^nexp
yline = f(xMinPlot,c)
p += line(((xline,yline),(xlabel,yline+offsets[i])), color='gray', thickness=0.5)
p += text('$c = 10^{{ {:.1f} }}$'.format(float(nexp)),
(xlabel, yline+offsets[i]), **text_options)

p.show(xmin=5*10^-2, xmax=10)


a b This approach requires to analyse each plot case by case and playing around to find a solution, but I am afraid there is nothing one can do to partially automate it. Also, I am not sure that I am doing this the best way, or whether the result could look better/more professional. a

### Legend attached to curve in plot ("PlotLabels")

Hello,

I have a plot with several curves (say, 5) and I need to clearly mark them.

The plot should be grayscale friendly (I am giving curves different shades, but it is not enough), and line style (dotted...) already has a different meaning. I am using a legend, but it goes in a separate box and does not really help a lot.

Since the different curves never cross in a given plot, just attaching the legend label to the curve tail would be great: how can I achieve this? To be clear, I am looking for an equivalent of Mathematica PlotLabels.

The following example gives an idea of the 'most overlapping' case I can be interested in (actually an exaggeration, a real plot would stop at nexp=2.5):

f(x,n) = e^(-1/(n*x))
listexp = srange(0.5, 3+0.1, 0.5)
lenght = float(len(listexp))
xMinPlot = 0.1

p = Graphics()
for i,nexp in enumerate(listexp) :
c = 10^nexp
p += plot_semilogx(f(x,c), (x, xMinPlot, 10), hue=i/lenght)

p.show()


Using slelievre answer (and imitating the PlotLabels idea, putting gray lines between plot and label), I came up with this:

text_options = {...}
offsets = [0.01, 0.01, 0.01, -0.02, -0.02, 0.02]
xlabel = xMinPlot*0.85
xline  = xMinPlot*0.97

for i,nexp in enumerate(listexp) :
c = 10^nexp
yline = f(xMinPlot,c)
p += line(((xline,yline),(xlabel,yline+offsets[i])), color='gray', thickness=0.5)
p += text('$c = 10^{{ {:.1f} }}$'.format(float(nexp)),
(xlabel, yline+offsets[i]), **text_options)

p.show(xmin=5*10^-2, xmax=10)


a b This approach requires to analyse each plot case by case and playing around to find a solution, but I am afraid there is nothing one can do to partially automate it. Also, I am not sure that I am doing this the best way, or whether the result could look better/more professional. a

### Legend attached to curve in plot ("PlotLabels")

Hello,

I have a plot with several curves (say, 5) and I need to clearly mark them.

The plot should be grayscale friendly (I am giving curves different shades, but it is not enough), and line style (dotted...) already has a different meaning. I am using a legend, but it goes in a separate box and does not really help a lot.

Since the different curves never cross in a given plot, just attaching the legend label to the curve tail would be great: how can I achieve this? To be clear, I am looking for an equivalent of Mathematica PlotLabels.

The following example gives an idea of the 'most overlapping' case I can be interested in (actually an exaggeration, a real plot would stop at nexp=2.5):

f(x,n) = e^(-1/(n*x))
listexp = srange(0.5, 3+0.1, 0.5)
lenght = float(len(listexp))
xMinPlot = 0.1

p = Graphics()
for i,nexp in enumerate(listexp) :
c = 10^nexp
p += plot_semilogx(f(x,c), (x, xMinPlot, 10), hue=i/lenght)

p.show()


Using slelievre answer (and imitating the PlotLabels idea, putting gray lines between plot and label), I came up with this:

text_options = {...}
offsets = [0.01, 0.01, 0.01, -0.02, -0.02, 0.02]
xlabel = xMinPlot*0.85
xline  = xMinPlot*0.97

for i,nexp in enumerate(listexp) :
c = 10^nexp
yline = f(xMinPlot,c)
p += line(((xline,yline),(xlabel,yline+offsets[i])), color='gray', thickness=0.5)
p += text('$c = 10^{{ {:.1f} }}$'.format(float(nexp)),
(xlabel, yline+offsets[i]), **text_options)

p.show(xmin=5*10^-2, xmax=10)


This approach requires to analyse each plot case by case and playing around to find a solution, but I am afraid there is nothing one can do to partially automate it. Also, I am not sure that I am doing this the best way, or whether the result could look better/more professional. aprofessional.