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
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')
-
Where is the difference to the existing answer?ImportanceOfBeingErnest– ImportanceOfBeingErnest2018年05月01日 17:09:32 +00:00Commented 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 outputAjax1234– Ajax12342018年05月01日 17:11:09 +00:00Commented May 1, 2018 at 17:11
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()
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....
Explore related questions
See similar questions with these tags.