2015-09-11 25 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

相關問題