如何构建显示两个变量之间依赖关系的条形图

How to build a barchart showing dependencies between two variables

我想创建以下条形图。我想在 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 

如果我明白你在问什么,我想你想要的是 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);

这是另一个示例图像,可能有助于阐明带状图和散点图的不同之处: