我需要比较4个班次(分类/分组)之间不同的每日数据集,使用条形图和折线图。我到处找遍了,没有找到一个有效的解决方案,不包括生成新的支点等等。在
我同时使用了matplotlib和seaborn,虽然我可以做一个或另一个(每个班次有不同颜色的条/线),但一旦我合并了另一个,要么其中一个消失了,要么其他异常情况发生,就像只有一个绘图点显示的那样。我已经看了所有的地方,有解决方案来表示单一系列的数据在两种图表类型,但没有一个进入多类别或分组为两种类型。在
数据示例:
report_date wh_id shift Head_Count UTL_R
3/17/19 55 A 72 25%
3/18/19 55 A 71 10%
3/19/19 55 A 76 20%
3/20/19 55 A 59 33%
3/21/19 55 A 65 10%
3/22/19 55 A 54 20%
3/23/19 55 A 66 14%
3/17/19 55 1 11 10%
3/17/19 55 2 27 13%
3/17/19 55 3 18 25%
3/18/19 55 1 23 100%
3/18/19 55 2 16 25%
3/18/19 55 3 12 50%
3/19/19 55 1 28 10%
3/19/19 55 2 23 50%
3/19/19 55 3 14 33%
3/20/19 55 1 29 25%
3/20/19 55 2 29 25%
3/20/19 55 3 10 50%
3/21/19 55 1 17 20%
3/21/19 55 2 29 14%
3/21/19 55 3 30 17%
3/22/19 55 1 12 14%
3/22/19 55 2 10 100%
3/22/19 55 3 17 14%
3/23/19 55 1 16 10%
3/23/19 55 2 11 100%
3/23/19 55 3 13 10%
^{pr2}$
这段代码让我离得最近。请注意,即使使用stacked = False
,它们仍然是堆叠的。我把设置改为真,什么也没变。在
所有我需要的是,酒吧是相邻的,以相同的颜色方案代表的变化
图表:
这里有两个解决方案(堆叠和未堆叠)。根据您的问题,我们将:
Head_Count
,在右y轴绘制UTL_R
。在report_date
将是我们的x轴shift
将代表图形的色调。在堆叠版本使用
pandas
默认打印功能,未堆叠版本使用seaborn
。在根据你的要求,我添加了一个100%堆积图。虽然它不完全是您在注释中要求的,但是您所要求的图形类型在读取时可能会造成一些混乱(这些值是基于堆栈的上行或堆栈的宽度)。另一种解决方案是使用100%堆积图。在
堆叠
100%堆积
^{pr2}$未堆叠
编辑2
这是您第二次请求的图形(堆栈,但堆栈n+1不是从堆栈n结束的位置开始的)。在
因为我们要做很多事情,所以它的参与程度要稍微高一些: -我们需要手动为df中的
shift
指定颜色 -一旦我们分配了颜色,我们将迭代每个日期范围和1)排序或Head_Count
值降序(以便我们在绘制图形时最大的sack在后面),2)绘制数据并将颜色分配给每个stacj -然后我们可以创建第二个y轴并绘制UTL_R
值 -然后我们需要为图例标签指定正确的颜色这个怎么样?在
相关问题 更多 >
编程相关推荐