【发布时间】:2022-01-19 18:28:32
【问题描述】:
我正在尝试绘制 4 个 KDE 图形(子图)或 1 个 4 线。 我有两列:
Region: Charges:
southeast 6000
southeast 5422
southwest 3222
northwest 4222
northwest 5555
northeast 6729
etc 1000s of rows..4 regions
我想可视化这 4 个区域的分布。
玩弄这个和错误消息(我知道这是不正确的)'Data must be 1-dimensional'。
fig, axes = plt.subplots(2, 2, sharex=True, figsize=(10,5))
fig.suptitle('Bigger 1 row x 2 columns axes with no data')
#axes[0].set_title('Title of the first chart')
reg_name = df2[['region','charges']].set_index('region')
southeast = reg_name.loc['southeast']
southwest = reg_name.loc['southwest']
northwest = reg_name.loc['northwest']
#c = df2.charges.values
#d = df2.region
# Set the dimensions of the plot
#widthInInches = 10
#heightInInches = 4
#plt.figure( figsize=(widthInInches, heightInInches) )
# Draw histograms and KDEs on the diagonal usin
#if( int(versionStrParts[1]) < 11 ):
# Use the older, now-deprectaed form
# ax = sns.distplot(c,
# kde_kws={"label": "Kernel Density", "color" : "black"},
# hist_kws={"label": "Histogram", "color" : 'lightsteelblue'})
#else:
# Use the more recent for
sns.kdeplot(ax=axes[0], x=southeast.index, y=southeast.values, color="black", label="Kernel Density")
axes[0].set_title(southeast.name)
sns.kdeplot(ax=axes[1], x=southwest.index, y=southwest.values, color="black", label="Kernel Density")
axes[1].set_title(southwest.name)
【问题讨论】:
标签: python matplotlib seaborn