2

I am using matplotlib to plot a Time-series data on Jupyter Notebook. My Time-series data is a numpy.array.
Here is my plot : enter image description here


How can I highlight a specific sub-sequence on that plot ?
Here is my example :

enter image description here

asked Jan 13, 2018 at 9:14
7
  • 2
    Try re-plotting that sub-range with a very thick line width (e.g. plot(x,y,lw=10, c='yellow', zorder=-1) and see if that is enough for your needs. The keyword zorder determines in which order different elements are drawn -- smaller values are drawn before larger values. Commented Jan 13, 2018 at 9:24
  • @ThomasKühn I tried but that not what I looking for. But do you completely understand the question ? I can explain more detail if you want. Commented Jan 13, 2018 at 10:19
  • @TrungTínTrần, did you try Thomas's solution? It should do exactly that what you were asking ... Commented Jan 13, 2018 at 10:38
  • @ThomasKühn, what about posting your comment as answer? ;-) I think it perfectly answers this question... Commented Jan 13, 2018 at 10:41
  • 1
    @MaxU I won't have time before the evening -- would you have time to write up an answer? Alternatively, chances are high that this is a duplicate ... Commented Jan 13, 2018 at 10:48

1 Answer 1

4

Here is a small demo based on @Thomas Kühn comment:

x = np.linspace(-10, 10, 100)
plt.plot(x, np.sin(x))
plt.plot(x[60:80], np.sin(x[60:80]), lw=10, c='yellow', zorder=-1)

Result:

enter image description here

answered Jan 13, 2018 at 10:58
3
  • thanks MaxU and Thomas. Now it's work !! I am just misunderstood the keyword x and y. Commented Jan 13, 2018 at 11:03
  • Perfect answer! You got my upvote already, just didn't have time to comment ;) Commented Jan 14, 2018 at 8:25
  • @ThomasKühn, thank you! I didn’t know the trick with the "zorder", so I have learned something new from your comment! :) Commented Jan 14, 2018 at 8:56

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.