Pandas stacked area chart with zero values
Asked Answered
D

1

10

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')
Decrescendo answered 2/2, 2017 at 21:56 Comment(6)
drop the rows with the values you don't want.Pascual
Not all of the values in the row are zero.Decrescendo
It's impossible to help with this kind of problem without code to generate a representative dataframe.Pascual
The code is reading other files and would be difficult to put on here. Is there a way to put the dataframe on from the code without the entire code?Decrescendo
I added sample code, but I don't know how to show the graph in here.Decrescendo
@LynetteBrooks save the graph as a file and then upload it to the question using the editing optionsGyre
G
10

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)
Gyre answered 6/6, 2017 at 13:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.