我试图绘制一个条形图,销售vs类别。下面是我的数据框
S2PName-Category S2BillDate totSale count
0 Beverages 2020-03-06 4452.62 252
1 Food 2020-03-06 36556.91 774
2 Others 2020-03-06 608.95 99
3 Snacks 2020-03-06 2662.75 139
4 Juice 2020-03-06 2139.49 40
5 IceCream 2020-03-06 135.00 4
6 OOB 2020-03-06 390.00 20
我的代码:
data = [go.Bar(x=df['S2PName-Category'].unique(),
y=df[df['S2PName-Category']==category]['totSale'],
name = category) for category in df['S2PName-Category'].unique()]
layout = go.Layout(title='Category wise performance',
xaxis = dict(title = 'Categories', automargin = True),
yaxis = dict(tickprefix= '₹', tickformat=',.2f',type='log',autorange = True),
hovermode = 'closest',
plot_bgcolor = colors['background'],
paper_bgcolor = colors['background'],
font = dict(color = colors['text'])
)
只有类别(“S2PName-category”)中的饮料在x轴上有分布,其余饮料没有分布。有人能指出哪里出了问题,以及如何解决这个问题吗?谢谢
试验2:我在尝试其他可能性,由于列表理解,我的条形图被分组,有没有办法得到要绘制的唯一类别
代码:
data = [go.Bar(x=df['S2PName-Category'],
y=df['totSale'],
name = category) for category in df['S2PName-Category'].unique()]
layout = go.Layout(title='Category wise performance',
xaxis = dict(title = 'Categories', automargin = True),
yaxis = dict(tickprefix= '₹', tickformat=',.2f',type='log',autorange = True),
hovermode = 'closest',
plot_bgcolor = colors['background'],
paper_bgcolor = colors['background'],
font = dict(color = colors['text'])
)
如果您提供的数据样本实际上代表了您的真实数据源,那么您可以设置一个带有
go.Figure()
的图形,并为每个'S2PName-Category'
添加一个单独的跟踪 如果这还不够,您必须提供更好的数据示例完整代码:
相关问题 更多 >
编程相关推荐