proplot icon indicating copy to clipboard operation
proplot copied to clipboard

stacked bar and barh plot with both postive and negative values

Open Mickychen00 opened this issue 2 years ago • 1 comments

I found that proplot's bar and barh plot function cannot plot stacked figure correctly with both postive and negative values. It means negative values stacked together and positive values stacked together, not mix them up. Pandas's own plot function work well. Whether there is a solution in proplot? btw proplot's format function is awesome!

Mickychen00 avatar Apr 07 '22 10:04 Mickychen00

Re: the format function, thanks! I agree :). Re: stacking with negative/positive bar values, I see what you're saying -- seems that pandas partitions values into two "stacks" (one negative stack, and one positive stack), while proplot simply naively adds successive bar heights to the previous bar heights (see below example).

Will come back to this sometime.

import numpy as np
import proplot as pplt
import pandas as pd
fig, axs = pplt.subplots(ncols=2, xlim=(-1, 2), xlocator=1, title=['Pandas', 'Proplot'])
data = np.random.rand(10, 10) * 10 - 5
data = np.array([[1, 2], [1, -2]])
data = pd.DataFrame(data)
data.plot.bar(stacked=True, ax=axs[0])
axs[1].bar(data, stacked=True, width=0.8, labels=[0, 1], legend=True)

iTerm2 9s8Fbc tmpjwod3gn8

lukelbd avatar Mar 29 '23 05:03 lukelbd