1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > scatter python cmap_python matplotlib:指定cmap来生成多颜色散射p

scatter python cmap_python matplotlib:指定cmap来生成多颜色散射p

时间:2022-01-22 00:38:09

相关推荐

scatter python cmap_python matplotlib:指定cmap来生成多颜色散射p

我尝试使用matplotlib和seaborn来创建散点图。如果整个绘图只有一种颜色,如下图所示:sns.regplot(x = pair[0], y = pair[1], data = d, fit_reg = False, ax = ax, x_jitter = True, scatter_kws = {'linewidths':0, 's':2, 'color':'r'})

但是,如果我需要每个数据点的颜色取决于col中的值,如:

^{pr2}$

其中pandas_df是熊猫数据帧,因此col是一系列RGB点,如:[1,0,0]

[0,1,0]

[1,0,0]

[0,1,0]

:

:

然后我得到了错误:IndexErrorTraceback (most recent call last)

in ()

15 #print dtype(col)

16 d.plot.scatter(*pair, ax=ax, c=col, linewidths=0, s=2, alpha = 0.7)

---> 17 sns.regplot(x = pair[0], y = pair[1], data = d, fit_reg = False, ax = ax, x_jitter = True, scatter_kws = {'linewidths':0, 's':2, 'cmap':"RGB", 'color':col})

18

19 fig.tight_layout()

/usr/local/lib/python2.7/dist-packages/seaborn/linearmodels.pyc in regplot(x, y, data, x_estimator, x_bins, x_ci, scatter, fit_reg, ci, n_boot, units, order, logistic, lowess, robust, logx, x_partial, y_partial, truncate, dropna, x_jitter, y_jitter, label, color, marker, scatter_kws, line_kws, ax)

777 scatter_kws["marker"] = marker

778 line_kws = {} if line_kws is None else copy.copy(line_kws)

--> 779 plotter.plot(ax, scatter_kws, line_kws)

780 return ax

781

/usr/local/lib/python2.7/dist-packages/seaborn/linearmodels.pyc in plot(self, ax, scatter_kws, line_kws)

328 # Draw the constituent plots

329 if self.scatter:

--> 330 self.scatterplot(ax, scatter_kws)

331 if self.fit_reg:

332 self.lineplot(ax, line_kws)

/usr/local/lib/python2.7/dist-packages/seaborn/linearmodels.pyc in scatterplot(self, ax, kws)

353 kws.setdefault("linewidths", lw)

354

--> 355 if not hasattr(kws['color'], 'shape') or kws['color'].shape[1] < 4:

356 kws.setdefault("alpha", .8)

357

IndexError: tuple index out of range

在这种情况下,我在分配颜色和cmap时做错了什么?谢谢!在

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。