1

Hi Seabron/Python community, I am trying to draw attention to a certain section of a plot I am building. My code looks like this:

plt.figure(figsize=(10, 10))
graph=sns.lineplot(x="variable", y="value", hue="Type", style="Type", 
             data=AWS_spot_vector_all)
graph.xaxis.set_major_locator(ticker.MultipleLocator(10))
graph.xaxis.set_major_formatter(ticker.FormatStrFormatter('%0.0f%%'))
graph.yaxis.set_major_formatter(ticker.StrMethodFormatter('{x:,.0f}')) 

The output of that code is the following:

My current chart

I want to add a box overlay to selectively mark horizontal regions across the whole axes, something like the green box here:

Geen box overlay

I understand that I need to use the fill_between function, but haven't figured out how.

  • First off, you need another name for the return value of `sns.lineplot` as it returns an `ax`. This will help a lot in finding your way in the matplotlib documentation. With `ax=sns.lineplot(...)` you can call for example `ax.axvspan(x0, x1, color='gold', alpha=0.3)`. Note that `fill_between` would color between two curves (or below/above a curve or ...). – JohanC Apr 11 '21 at 21:40

0 Answers0