I’m making a visualization of historical stock data for a project, and I’d like to highlight regions of drops. For instance, when the stock is experiencing significant drawdown, I would like to highlight it with a red region.
Can I do this automatically, or will I have to draw a rectangle or something?
Have a look at
axvspan(and axhspan for highlighting a region of the y-axis).If you’re using dates, then you’ll need to convert your min and max x values to matplotlib dates. Use
matplotlib.dates.date2numfordatetimeobjects ormatplotlib.dates.datestr2numfor various string timestamps.