13

I have the following graph, consisting of several lines:

Sample line plot

Now, I would like to label all the lines in the plot. However, using legend() crams all the labels together in a box, which makes the plot somewhat difficult to interpret. What I'd like to to instead is to use inline labels. My ideal output would use labels like the following matplotlib contour plot, but with text labels for lines instead of numbers:

Sample contour plot

I haven't been able to find out how to do this in the matplotlib documentation. Is there a way to achieve this? If not, what other software could I use to generate this type of plot?

Daniel
  • 695
  • 7
  • 20
  • 3
    This is a duplicate of http://stackoverflow.com/q/19876882/2870069! You'll find a possible solution there. – Jakob Feb 04 '14 at 22:08
  • 2
    Thanks, good find! This seems to work well for straight lines. Is there a way to fit the text to a path like in SVG (e.g., https://developer.mozilla.org/en/docs/Web/SVG/Element/textPath)? – Daniel Feb 07 '14 at 09:16
  • Similar also to: http://stackoverflow.com/questions/16992038/inline-labels-in-matplotlib – 0 _ Apr 19 '15 at 01:25
  • This thread contains the best solution: http://stackoverflow.com/questions/16992038/inline-labels-in-matplotlib][1] – trickleboast Feb 06 '17 at 20:56
  • Possible duplicate of [Inline labels in Matplotlib](http://stackoverflow.com/questions/16992038/inline-labels-in-matplotlib) – trblnc Mar 23 '17 at 16:42

1 Answers1

2

May I suggest another solution to your problem. Since in your case legend overlaps the charts you might just want to move the legend outside of the plot.

Method do move legend outside of plot is described here: Moving matplotlib legend outside of the axis makes it cutoff by the figure box

Community
  • 1
  • 1
jb.
  • 23,300
  • 18
  • 98
  • 136