0

I wonder below the picture, how could I label texts on different phases of the lines?

enter image description here

For convenience, I provide an easy case as below:Please tell me, how to mark the two sections with f(t)=2 and f(t)=t? I expect the label is automatically attached to the line?

enter image description here

import numpy as np
import matplotlib.pyplot as plt

def f(t):
  return np.where(t>=2,t,2)
t=np.arange(-4, 6, 0.1)

plt.axis([-4,6,1,4])
plt.plot(t,f(t))]
plt.text(-3,3.5,'How to mark the two sections with\n f(t)=2 and f(t)=t?\nI expect the label automatically \natached to the line')
plt.show()
  • I do not know what do you mean? I can't describe my problem well in English language for I´m a Chinese. I posted two pictures, I want to label lines in the first style, and I provide a simpler case as below. So can you help me? Thank you! – John Paul Qiang Chen Jan 28 '16 at 13:48
  • In your real problem, do you know f(t) ? or do you only have the results of f(t) ? – jrjc Jan 28 '16 at 13:50
  • It's here :f(t)=2, when t<2. f(t) = t, when t >=2. Code like this def f(t): return np.where(t>=2,t,2) t=np.arange(-4, 6, 0.1) – John Paul Qiang Chen Jan 28 '16 at 13:54
  • Here's some relevant links: http://stackoverflow.com/questions/19876882/print-string-over-plotted-line-mimic-contour-plot-labels, http://stackoverflow.com/questions/16992038/inline-labels-in-matplotlib. – Mel Jan 28 '16 at 13:59

0 Answers0