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

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

Sign up to request clarification or add additional context in comments.

2 Comments

Where is the difference to the existing answer?
@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
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()

Comments

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....

1 Comment

That's a nice hack!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.