I created a pandas plot from two dataframes:
ttload.plot(legend=True, figsize=(12,7))
zzload.plot(legend=False)
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?
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.
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.
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.
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.
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.
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.
ax = ttload.plot(legend=True, figsize=(12,7))
zzload.plot(legend=False,ax=ax)
ax.fill_between(ttload.index,ttload['value'], zzload['value'])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With