Home > other >  Matplotlib : fill subarea of a Graph
Matplotlib : fill subarea of a Graph

Time:02-19

I am using series and matplotlib to plot some graph like that :

enter image description here

basically, I build them using

ax.plot(df)

where df is a series with index : 'Sep', 'Oct', 'Nov', .... and value some number.

What I wanted to have is fill the background, but only after the 'Mar' index (for example) Currently the only things I was able to do is to create a series with only 'Mar' to 'Jul' as index with constant value to identify the "area", but ideally I would fill the background with some color to identify clearly both part of the graph (before mars it is data realised, after it is some prediction of my algo)

For example, if I use :

ax.set_facecolor('silver')

I have this result :

enter image description here

but that should appear only after 'Mars', but I don't find any way to filter the background to apply this kind of function

CodePudding user response:

As mentioned, you can use demo screenshot

  • Related