9

I want to mark certain indices in the line plot. I have referred to the following question on stack overflow and written the following:

plt.plot(range(len(y)), y, '-bD', markevery=rare_cases, label='%s' % target_var_name)

However, this produces the following: enter image description here

How can I keep the line plot in blue but make the markers in red ?

1 Answer 1

16

From the documentation of plt.plot:

matplotlib.pyplot.plot(*args, scalex=True, scaley=True, data=None, **kwargs)

The function takes **kwargs:

**kwargsLine2D properties, optional kwargs are used to specify properties like a line label (for auto legends), line-width, antialiasing, marker face color [...] Here is a list of available Line2D properties: [...]

markeredgecolor or mec color
markeredgewidth or mew float
markerfacecolor or mfc color
markerfacecoloralt or mfcalt color

So, you can feed markerfacecolor and markeredgecolor as keyword arguments:

x = np.random.randint(0,10,5)
y = np.random.randint(0,10,5)
    
plt.plot(x, y, '-bD',  c='blue', mfc='red', mec='k')

enter image description here

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.