Area#

import hvplot.pandas  # noqa

area can be used to color the area under a line or to color the space between two lines.

from bokeh.sampledata.degrees import data

data.tail()
Year Agriculture Architecture Art and Performance Biology Business Communications and Journalism Computer Science Education Engineering English Foreign Languages Health Professions Math and Statistics Physical Sciences Psychology Public Administration Social Sciences and History
37 2007 47.605026 43.100459 61.4 59.411993 49.000459 62.5 17.6 78.721413 16.8 67.874923 70.2 85.4 44.1 40.7 77.1 82.1 49.3
38 2008 47.570834 42.711730 60.7 59.305765 48.888027 62.4 17.8 79.196327 16.5 67.594028 70.2 85.2 43.3 40.7 77.2 81.7 49.4
39 2009 48.667224 43.348921 61.0 58.489583 48.840474 62.8 18.1 79.532909 16.8 67.969792 69.3 85.1 43.3 40.7 77.1 82.0 49.4
40 2010 48.730042 42.066721 61.3 59.010255 48.757988 62.5 17.6 79.618625 17.2 67.928106 69.0 85.0 43.1 40.2 77.0 81.7 49.3
41 2011 50.037182 42.773438 61.2 58.742397 48.180418 62.2 18.2 79.432812 17.5 68.426730 69.5 84.8 43.1 40.1 76.7 81.9 49.2

First we’ll look at a single curve, where we are enforcing the y axis must be between 0 and 100 and we set the background color.

data.hvplot.area(
    x='Year', y='Computer Science',
    label='% of Computer Science Degrees Earned by Women',
    ylim=(0, 100), width=500, height=400, bgcolor='goldenrod',
)
import pandas as pd
from bokeh.sampledata.stocks import MSFT

df = pd.DataFrame(MSFT)
df['date'] = pd.to_datetime(df.date)
df.head()
date open high low close volume adj_close
0 2000-03-01 89.62 94.09 88.94 90.81 106889800 33.68
1 2000-03-02 91.81 95.37 91.12 93.37 106932600 34.63
2 2000-03-03 94.75 98.87 93.87 96.12 101435200 35.65
3 2000-03-06 96.00 97.37 90.12 90.62 93609400 33.61
4 2000-03-07 96.12 97.50 91.94 92.87 135061000 34.45

To color the area between two curves, include both a y and a y2.

df[df.date.dt.year == 2000].hvplot.area(x='date', y='low', y2='high')

When multiple y values are passed, they are stacked by default.

df.hvplot.area(x='date', y=['open', 'close'])

Area plots can also be unstacked:

df.hvplot.area(x='date', y=['open', 'close'], stacked=False,
               groupby='date.year', legend='bottom_right', width=500)
This web page was generated from a Jupyter notebook and not all interactivity will work on this website.