Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 确保seaborn中条形图的颜色一致_Python_Jupyter Notebook_Seaborn - Fatal编程技术网

Python 确保seaborn中条形图的颜色一致

Python 确保seaborn中条形图的颜色一致,python,jupyter-notebook,seaborn,Python,Jupyter Notebook,Seaborn,我一直在使用Jupyter笔记本处理一个数据集,我正在比较通过仓库移动的物品数量与这些物品的拣货数量 我正在使用Seaborn渲染我的情节 我在一个网格中有两个条形图,在数据未排序的情况下,这些图如下所示: 使用以下代码: plt.figure(1, figsize=(20,15)) gs = gridspec.GridSpec(2, 2) plt.subplot(gs[0,0], title="Count of SKU pick events") sns.barplot(x='qty',

我一直在使用Jupyter笔记本处理一个数据集,我正在比较通过仓库移动的物品数量与这些物品的拣货数量

我正在使用Seaborn渲染我的情节

我在一个网格中有两个条形图,在数据未排序的情况下,这些图如下所示:

使用以下代码:

plt.figure(1, figsize=(20,15))
gs = gridspec.GridSpec(2, 2)

plt.subplot(gs[0,0], title="Count of SKU pick events")
sns.barplot(x='qty', y='sku', data=sku_count, palette='Spectral')
plt.subplot(gs[0,1], title="Sum of SKU quantities picked")
sns.barplot(x='qty', y='sku',data=sku_sum, palette='Spectral')
可以看出,两个图中每个条的颜色对应

一旦我按照每个绘图的各自数量(计数与总和)对数据进行排序,问题就会出现:

并使用类似代码重新渲染图形:

plt.figure(2, figsize=(20,15))
gs = gridspec.GridSpec(2, 2)

plt.subplot(gs[0,0], title="Count of SKU pick events")
sns.barplot(x='qty', y='sku', data=sku_count, palette='Spectral', hue_order=h_o)
plt.subplot(gs[0,1], title="Sum of SKU quantities picked")
sns.barplot(x='qty', y='sku',data=sku_sum, palette='Spectral', hue_order=h_o)

从第4行向下,系列颜色不对应

我想在列表中定义我的色调序列,稍后我使用
hue
hue\u-order
引用该序列:

#hue_order handling (TODO: NOT WORKING YET!)
h_o = ['A','B','C','D','E','F','G','H']
我尝试过使用
hue
,但我认为这是用于向数据添加其他维度的,使用此代码:

plt.figure(3, figsize=(20,15))
gs = gridspec.GridSpec(2, 2)

plt.subplot(gs[0,0], title="Count of SKU pick events")
sns.barplot(x='qty', y='sku', data=sku_count, palette='Spectral', hue=h_o)
plt.subplot(gs[0,1], title="Sum of SKU quantities picked")
sns.barplot(x='qty', y='sku',data=sku_sum, palette='Spectral', hue=h_o)
产生以下结果:

这绝对不是我需要的


关于如何在不同数据的同一系列的不同图形之间锁定色调,有什么建议吗?

Hi不应该只是hue=“sku”?(现在无法测试,只需添加评论)很高兴为您测试!一秒钟…@HubertDudek我之前测试过这个,现在再次运行它…不幸的是,产生的结果与问题中的最后一个数字相同,同时技术上产生了正确的答案…有解决方案吗?缺少相同的一致性。我认为在你的例子中,一个解决方案可能是将组F和H相加,但值为零。
plt.figure(3, figsize=(20,15))
gs = gridspec.GridSpec(2, 2)

plt.subplot(gs[0,0], title="Count of SKU pick events")
sns.barplot(x='qty', y='sku', data=sku_count, palette='Spectral', hue=h_o)
plt.subplot(gs[0,1], title="Sum of SKU quantities picked")
sns.barplot(x='qty', y='sku',data=sku_sum, palette='Spectral', hue=h_o)