1

How can I use matplotlib or any other library to draw line graphs in Python with highlighted/prominent data points, something like the one shown in the image?enter image description here

asked May 1, 2018 at 17:01

3 Answers 3

3

You can create two plots, one for your main data, and the other, with the prominent data points:

import matplotlib.pyplot as plt
#example data below:
main_data = [[45, 23, 13, 4, 5, 66], [33, 23, 4, 23, 5, 56]]
highlight = [[46, 42], [34, 10]]
plt.plot(*main_data)
plt.scatter(*highlight, marker='v', color='r')

enter image description here

answered May 1, 2018 at 17:08
2
  • Where is the difference to the existing answer? Commented May 1, 2018 at 17:09
  • 3
    @ImportanceOfBeingErnest I just noticed the other answer, however, this response provides 1. Example data 2. markers in the style as the OP wished 3. an example output Commented May 1, 2018 at 17:11
2

It might be worth while to just plot each point separately as a different color!

Something like this maybe:

import matplotlib.pyplot as plt
x = [1,2,3,4,5]
y = [1,2,3,4,5]
plt.plot(x,y, 'bo-')
plt.plot(x[1],y[1], 'r*')
plt.show()
answered May 1, 2018 at 17:04
0
2

I came here because I had a list of the x and y values and was creating a line graph out of it in matplotlib. I simply want the data points to be highlighted as they are in the graph the question shows. The other posts don't give an answer to this.

I was able to solve it by simply adding the marker parameter to the plt.plot statement:

plt.plot(x_values, y_values, marker='o')

P.S. My post is not to answer the OP's question but rather to help anybody else who arrives at this question with the same doubt as me....

answered Jun 23, 2020 at 17:53
1
  • That's a nice hack! Commented Mar 6, 2024 at 6:19

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.