Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas stacked area chart with zero values

I am creating a stacked area chart using pandas df.plot(kind = area). Some of my data values are zero at some times. I would like to not have the line show where the value is zero. Is it possible to hide the line while still showing the area?

Here is basic code that makes a simple graph. I don't want the red line to show between 3 and 4 because the values are 0.

import numpy as np
import pandas as pd
data = np.array([np.arange(10)]*3).T
df = pd.DataFrame(data, columns = ['A','B','C'])
df['C']=np.where(df.index==4,0,df['C'])
df['C']=np.where(df.index==3,0,df['C'])
df.plot(kind='area')
like image 388
Lynette Brooks Avatar asked Feb 02 '17 21:02

Lynette Brooks


1 Answers

I have finally worked out the solution to this. Other places suggested edgecolor etc but it didn't solve the problem. linewidth, however, does.

linewidth=0

or, in your case, use the line of code:

df.plot(kind='area', linewidth=0)
like image 200
mjp Avatar answered Sep 21 '22 17:09

mjp