Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

plotting fill_between() in pandas

I created a pandas plot from two dataframes:

ttload.plot(legend=True, figsize=(12,7))
zzload.plot(legend=False)

enter image description here

Now, I would like to use the fill_between function to generate a shaded region between 0 (the orange line) and the min and max values of the blue line.

I have saved the min and max values of blue in variables w_min and w_max.

Any ideas on how I can do that?

like image 857
harald12345 Avatar asked Jul 20 '17 18:07

harald12345


People also ask

How do you fill between two curves in Python?

fill_between() is used to fill area between two horizontal curves. Two points (x, y1) and (x, y2) define the curves. this creates one or more polygons describing the filled areas. The 'where' parameter can be used to selectively fill some areas.

How do you fill a line with color in python?

With the use of the fill_between() function in the Matplotlib library in Python, we can easily fill the color between any multiple lines or any two horizontal curves on a 2D plane.

How do I plot a diagram in pandas?

Plotting Pandas uses the plot () method to create diagrams. We can use Pyplot, a submodule of the Matplotlib library to visualize the diagram on the screen. Read more about Matplotlib in our Matplotlib Tutorial.

How do I convert pandas data to matplotlib data?

Pandas registers a converter in matplotlib.units.registry which converts a number of datetime types (such as pandas DatetimeIndex, and numpy arrays of dtype datetime64) to matplotlib datenums, but it does not handle Pandas Series with dtype datetime64. fill_between checks for and uses a converter to handle the data if it exists.

What is a Dataframe plot in Python?

Now that you know that the DataFrame object’s .plot () method is a wrapper for Matplotlib’s pyplot.plot (), let’s dive into the different kinds of plots you can create and how to make them. The next plots will give you a general overview of a specific column of your dataset.

What does fill_between do in pandas?

fill_between checks for and uses a converter to handle the data if it exists. Show activity on this post. As WillZ pointed out, Pandas 0.21 broke unutbu's workaround.


1 Answers

ax = ttload.plot(legend=True, figsize=(12,7))
zzload.plot(legend=False,ax=ax)

ax.fill_between(ttload.index,ttload['value'], zzload['value'])

enter image description here

like image 59
Scott Boston Avatar answered Sep 20 '22 15:09

Scott Boston