Python ValueError:s必须是标量,或与seaborn可视化中的x和y大小相同
我正在尝试绘制一个条带图,其中大小应该是DataFrame的一列。这是我的数据帧“计数”Python ValueError:s必须是标量,或与seaborn可视化中的x和y大小相同,python,matplotlib,seaborn,Python,Matplotlib,Seaborn,我正在尝试绘制一个条带图,其中大小应该是DataFrame的一列。这是我的数据帧“计数” BPXDI1 BPXSY1 Groups 0 0.0 98.0 2 1 0.0 104.0 1 2 0.0 116.0 1 3 0.0 120.0 1 4 0.0 124.0 1 列组和其他列的长度完全相同 len(counts.Groups) 输出为1061 同样,数据帧
BPXDI1 BPXSY1 Groups
0 0.0 98.0 2
1 0.0 104.0 1
2 0.0 116.0 1
3 0.0 120.0 1
4 0.0 124.0 1
列组和其他列的长度完全相同
len(counts.Groups)
输出为1061
同样,数据帧的长度也是1061。
但当我尝试运行此代码时:
fig, ax = plt.subplots(figsize=(16,10), dpi= 80)
sns.stripplot(counts.BPXDI1, counts.BPXSY1, s=counts.Groups, ax=ax)
plt.title("Stripplot for Systolic vs Diastolic Blood Pressure", fontsize=20)
plt.show()
我得到这个错误:
ValueError Traceback (most recent call last)
<ipython-input-208-2e1bd399f6e4> in <module>
1 fig, ax = plt.subplots(figsize=(16,10), dpi= 80)
----> 2 sns.stripplot(counts.BPXDI1, counts.BPXSY1, s=counts.Groups, ax=ax)
3
4 plt.title("Stripplot for Systolic vs Diastolic Blood Pressure", fontsize=20)
5 plt.show()
~\Anaconda3\lib\site-packages\seaborn\categorical.py in stripplot(x, y, hue, data, order, hue_order, jitter, dodge, orient, color, palette, size, edgecolor, linewidth, ax, **kwargs)
2799 linewidth=linewidth))
2800
-> 2801 plotter.plot(ax, kwargs)
2802 return ax
2803
~\Anaconda3\lib\site-packages\seaborn\categorical.py in plot(self, ax, kws)
1202 def plot(self, ax, kws):
1203 """Make the plot."""
-> 1204 self.draw_stripplot(ax, kws)
1205 self.add_legend_data(ax)
1206 self.annotate_axes(ax)
~\Anaconda3\lib\site-packages\seaborn\categorical.py in draw_stripplot(self, ax, kws)
1178 kws.update(c=palette[point_colors])
1179 if self.orient == "v":
-> 1180 ax.scatter(cat_pos, strip_data, **kws)
1181 else:
1182 ax.scatter(strip_data, cat_pos, **kws)
~\Anaconda3\lib\site-packages\matplotlib\__init__.py in inner(ax, data, *args, **kwargs)
1436 def inner(ax, *args, data=None, **kwargs):
1437 if data is None:
-> 1438 return func(ax, *map(sanitize_sequence, args), **kwargs)
1439
1440 bound = new_sig.bind(ax, *args, **kwargs)
~\Anaconda3\lib\site-packages\matplotlib\cbook\deprecation.py in wrapper(*inner_args, **inner_kwargs)
409 else deprecation_addendum,
410 **kwargs)
--> 411 return func(*inner_args, **inner_kwargs)
412
413 return wrapper
~\Anaconda3\lib\site-packages\matplotlib\axes\_axes.py in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, plotnonfinite, **kwargs)
4446 s = np.ma.ravel(s)
4447 if len(s) not in (1, x.size):
-> 4448 raise ValueError("s must be a scalar, or the same size as x and y")
4449
4450 c, colors, edgecolors = \
ValueError: s must be a scalar, or the same size as x and y
有人能帮忙吗?这对我来说毫无意义
提前谢谢 大小是seaborn的选项,s不是,而是传递给plt。散射:
输出:
sns.stripplotcounts.BPXDI1,counts.BPXSY1,size=counts.Groups,ax=ax
我改了尺寸。但这对我不起作用。还有其他建议吗@我不知道为什么。如我在回答中所示,它与您的样本数据一起工作。你说它对我不起作用是什么意思,哪里出了问题?你的代码对我也起作用。您的seaborn安装或数据帧有问题。请提供您的数据框架。这不提供问题的答案。一旦你有足够的钱,你将能够;相反-
sns.stripplot(counts.BPXDI1, counts.BPXSY1,size=counts.Groups*50)