["python","matplotlib"]
How to get color of most recent plotted line in Python's plt

I plot a line without specifying the color (think: plt.plot(x,y)). Say the color comes out blue. Question: How do I obtain this color from the plt object so that I can put it into a variable? Seems like this is close (and potentially the solution): p = plt.plot(x,y) color = p[0].get_color() Updated question: I am not sure I understand the "0" index: Does p[0] always access the most recent plotted line?
In your example, p is a list of Line2D object. In that example you have only one line object, p[0]. The following is an example plotting three lines. As more line is added, it is appended to the p. So if you want the color of the last plot, it will be p[-1].get_color(). import numpy as np import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) p = plt.plot(x,y, x,y*2, x,y*3) # make three line plots type(p) # list type(p[0]) # <class 'matplotlib.lines.Line2D'> p[0].get_color() # 'b' p[1].get_color() # 'g' p[2].get_color() # 'r'