我想使用带有循环范围的 plt.subplots() 来绘制 swarmplot 当特征 plate 是不同的值时。
所以我用一个简单的图来编码,它绝对是正确的。
#I just use i = 5 to specify a value
i = 5
sns.swarmplot(b[b['plate'] == 'BK0000' + str(i)]['plate'],\
b[b['plate'] == 'BK0000' + str(i)]['tradeMoney'])
但是当我尝试按如下方式编码时出现了问题:
nrows, ncols = 64, 1
fig, ax = plt.subplots(nrows=nrows, ncols=ncols, figsize=(9, 72), dpi=120)
month_cnt = 1
for i in range(nrows):
i_ = i
if (i < 10):
i = '0' + str(i)
if (i == 32 | i == 58):
continue
sns.swarmplot(b[b['plate'] == 'BK000' + str(i)]['plate'],\
b[b['plate'] == 'BK000' + str(i)]['tradeMoney'],\
ax=ax[i_])
ax[i_].set_xlabel('BK000' + str(i))
ax[i_].set_ylabel('tradeMoney')
错误消息再次让我困惑。
---------------------------------------------------------------------------
ValueError Traceback (most recent call last) in
12 sns.swarmplot(b[b['plate'] == 'BK000' + str(i)]['plate'],\
13 b[b['plate'] == 'BK000' + str(i)]['tradeMoney'],\
---> 14 ax=ax[i_])
15
16 ax[i_].set_xlabel('BK000' + str(i))~\Anaconda3\lib\site-packages\seaborn\categorical.py in swarmplot(x, y, hue, data, order, hue_order, dodge, orient, color, palette, size, edgecolor, linewidth, ax, **kwargs)
2975
2976 plotter = _SwarmPlotter(x, y, hue, data, order, hue_order,
-> 2977 dodge, orient, color, palette)
2978< if ax is None:
2979 ax = plt.gca()~\Anaconda3\lib\site-packages\seaborn\categorical.py in init(self, x, y, hue, data, order, hue_order, dodge, orient, color, palette)
1213 """Initialize the plotter."""
1214
self.establish_variables(x, y, hue, data, orient, order, hue_order) ->
1215 self.establish_colors(color, palette, 1)
1216
1217 # Set object attributes~\Anaconda3\lib\site-packages\seaborn\categorical.py in establish_colors(self, color, palette, saturation) 313 # Determine the gray color to use for the lines framing the plot
314 light_vals = [colorsys.rgb_to_hls(*c)1 for c in rgb_colors]
--> 315 lum = min(light_vals) * .6
316 gray = mpl.colors.rgb2hex((lum, lum, lum))
317ValueError: min() arg is an empty sequence
而且情节都是空白的。
b['plate'].unique()
array(['BK00001', 'BK00002', 'BK00003', 'BK00004', 'BK00005', 'BK00006',
'BK00007', 'BK00008', 'BK00009', 'BK00010', 'BK00011', 'BK00012',
'BK00013', 'BK00014', 'BK00015', 'BK00016', 'BK00017', 'BK00018',
'BK00019', 'BK00020', 'BK00021', 'BK00022', 'BK00023', 'BK00024',
'BK00025', 'BK00026', 'BK00027', 'BK00028', 'BK00029', 'BK00030',
'BK00031', 'BK00033', 'BK00034', 'BK00035', 'BK00036', 'BK00037',
'BK00038', 'BK00039', 'BK00040', 'BK00041', 'BK00042', 'BK00043',
'BK00044', 'BK00045', 'BK00046', 'BK00047', 'BK00048', 'BK00049',
'BK00050', 'BK00051', 'BK00052', 'BK00053', 'BK00054', 'BK00055',
'BK00056', 'BK00057', 'BK00059', 'BK00060', 'BK00061', 'BK00062',
'BK00063', 'BK00064', 'BK00065', 'BK00066'], dtype=object)
即使我之前搜索过它,我也无法通过错误消息修复它。
谁能帮帮我?
提前致谢。
请您参考如下方法:
在第一次迭代期间,您似乎正在尝试在空数据帧上绘制群图。检查以确保 BK00000 存在或跳过绘制该值。
