proplot-dev / proplot

🎨 A succinct matplotlib wrapper for making beautiful, publication-quality graphics
https://proplot.readthedocs.io
MIT License
1.11k stars 102 forks source link

stacked bar and barh plot with both postive and negative values #355

Open Mickychen00 opened 2 years ago

Mickychen00 commented 2 years ago

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!

lukelbd commented 1 year ago

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