2015-09-11 28 views
-1

我想创建以下条形图。在X轴上,我想显示train['temp]的值,而在Y轴上 - train['icecream_demand']。请注意,train['temp']具有连续值,而train['icecream_demand']具有离散值。如何构建显示两个变量之间相关性的条形图

我不想构建散点图。这个想法是为了展示不同温度范围的典型冰淇淋需求。

我不提供样本数据,因为我只是寻找一些如何构建相同图的例子。

更新: 为了便于说明,我仍然想提供一些来自train的数据。

   datetime season holiday workingday weather temp atemp \ 
0 2011-01-01 00:00:00  1  0   0  1 9.84 14.395 
1 2011-01-01 01:00:00  1  0   0  1 9.02 13.635 
2 2011-01-01 02:00:00  1  0   0  1 9.02 13.635 
3 2011-01-01 03:00:00  1  0   0  1 9.84 14.395 
4 2011-01-01 04:00:00  1  0   0  1 9.84 14.395 

    humidity windspeed icecream_demand 
0  81   0 16 
1  80   0 40 
2  80   0 32 
3  75   0 13 
4  75   0 1 
+1

所以做冰淇淋的需求映射到特定范围在你的数据温度?如果是这样,难道你不能相应地把你的温度,然后绘制你的条形图? – areuexperienced

+0

@areuexperienced:请检查我的更新。你能举一些例子来说明你的想法吗? (带有“虚拟”数据) –

回答

1

如果我理解你的要求,我觉得你想要什么Seaborn称之为“stripplot”。这里有一个超简化的例子:

from matplotlib import pyplot as plt 
import pandas as pd 
import seaborn as sb 

ic 

    icecream_demand temp 
0 16 9.84 
1 40 9.02 
2 32 9.02 
3 13 9.84 
4 1 9.84 

ic.dtypes #to show that this can work with categorical data 

icecream_demand  object 
temp    float64 
dtype: object 

sb.stripplot(x="temp", y="icecream_demand", data=ic); 

enter image description here

再举一例图像,可能有助于阐明什么是关于stripplots和散点图不同:

enter image description here

相关问题