Python 如何为Seaborn Jointplot中的单个标记着色?

Python 如何为Seaborn Jointplot中的单个标记着色?,python,plot,colors,scatter-plot,seaborn,Python,Plot,Colors,Scatter Plot,Seaborn,我相信seaborn想要RGBA颜色格式,所以我给了它一个RGBA元组列表,就像matplotlib一样,但它不喜欢它。我尝试了一些类似于g=sns.jointplot(plotdataandstuff)的操作,但我不知道如何导航对象 u = np.array([ 3.41959, 1.79315, 1.17229, 1.59909, 1.27337, 1.21917, 2.60591, 2.0571 , 1.83865, 1.94869]) v = np.array([238614, 1667

我相信
seaborn
想要
RGBA
颜色格式,所以我给了它一个
RGBA
元组列表,就像
matplotlib
一样,但它不喜欢它。我尝试了一些类似于
g=sns.jointplot(plotdataandstuff)
的操作,但我不知道如何导航
对象

u = np.array([ 3.41959, 1.79315, 1.17229, 1.59909, 1.27337, 1.21917, 2.60591, 2.0571 , 1.83865, 1.94869])
v = np.array([238614, 166714, 152668, 131310, 131249, 130562, 118618, 117329, 101841, 87626])
c = np.array([(0.38998137426811552, 0.61096214975059782, 0.40096663322878834, 1.0), 
              (0.91819597903385741, 0.79247826098536023, 0.76754610185633376, 1.0), 
              (0.80693280982205806, 0.72756928157840872, 0.59917426429032361, 1.0), 
              (0.67210067882600855, 0.69086449405289441, 0.48640673089730696, 1.0), 
              (0.57590730770024134, 0.66895624366124595, 0.43845220910273563, 1.0), 
              (0.63252315055536124, 0.68193477278802606, 0.4639878928469835, 1.0), (
                  0.72522872317321141, 0.70350066480196072, 0.52329091024506846, 1.0), 
              (0.67210067882600855, 0.69086449405289441, 0.48640673089730696, 1.0), 
              (0.93684201381384091, 0.81480601869516889, 0.81083911715694279, 1.0), 
              (0.83654311363401856, 0.73919037695009648, 0.63434086709274395, 1.0)], dtype=object)
sns.jointplot(x=u, y=v, color=c)
这是错误

TypeError                                 Traceback (most recent call last)
/Users/jespinoz/anaconda/lib/python3.5/site-packages/matplotlib/colors.py in to_rgba(c, alpha)
    140     try:
--> 141         rgba = _colors_full_map.cache[c, alpha]
    142     except (KeyError, TypeError):  # Not in cache, or unhashable.

TypeError: unhashable type: 'numpy.ndarray'

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
/Users/jespinoz/anaconda/lib/python3.5/site-packages/matplotlib/colors.py in _to_rgba_no_colorcycle(c, alpha)
    191     try:
--> 192         c = tuple(map(float, c))
    193     except TypeError:

TypeError: only length-1 arrays can be converted to Python scalars

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-69-48b550e1edb6> in <module>()
     13               (0.93684201381384091, 0.81480601869516889, 0.81083911715694279, 1.0),
     14               (0.83654311363401856, 0.73919037695009648, 0.63434086709274395, 1.0)], dtype=object)
---> 15 sns.jointplot(x=u, y=v, color=c)

/Users/jespinoz/anaconda/lib/python3.5/site-packages/seaborn/distributions.py in jointplot(x, y, data, kind, stat_func, color, size, ratio, space, dropna, xlim, ylim, joint_kws, marginal_kws, annot_kws, **kwargs)
    789     if color is None:
    790         color = color_palette()[0]
--> 791     color_rgb = mpl.colors.colorConverter.to_rgb(color)
    792     colors = [set_hls_values(color_rgb, l=l) for l in np.linspace(1, 0, 12)]
    793     cmap = blend_palette(colors, as_cmap=True)

/Users/jespinoz/anaconda/lib/python3.5/site-packages/matplotlib/colors.py in to_rgb(arg)
    307         if *arg* is *RGBA*, the *A* will simply be discarded.
    308         """
--> 309         return to_rgb(arg)
    310 
    311     @staticmethod

/Users/jespinoz/anaconda/lib/python3.5/site-packages/matplotlib/colors.py in to_rgb(c)
    242     """Convert `c` to an RGB color, silently dropping the alpha channel.
    243     """
--> 244     return to_rgba(c)[:3]
    245 
    246 

/Users/jespinoz/anaconda/lib/python3.5/site-packages/matplotlib/colors.py in to_rgba(c, alpha)
    141         rgba = _colors_full_map.cache[c, alpha]
    142     except (KeyError, TypeError):  # Not in cache, or unhashable.
--> 143         rgba = _to_rgba_no_colorcycle(c, alpha)
    144         try:
    145             _colors_full_map.cache[c, alpha] = rgba

/Users/jespinoz/anaconda/lib/python3.5/site-packages/matplotlib/colors.py in _to_rgba_no_colorcycle(c, alpha)
    192         c = tuple(map(float, c))
    193     except TypeError:
--> 194         raise ValueError("Invalid RGBA argument: {!r}".format(orig_c))
    195     if len(c) not in [3, 4]:
    196         raise ValueError("RGBA sequence should have length 3 or 4")

ValueError: Invalid RGBA argument: array([[0.3899813742681155, 0.6109621497505978, 0.40096663322878834, 1.0],
       [0.9181959790338574, 0.7924782609853602, 0.7675461018563338, 1.0],
       [0.8069328098220581, 0.7275692815784087, 0.5991742642903236, 1.0],
       [0.6721006788260085, 0.6908644940528944, 0.48640673089730696, 1.0],
       [0.5759073077002413, 0.668956243661246, 0.43845220910273563, 1.0],
       [0.6325231505553612, 0.6819347727880261, 0.4639878928469835, 1.0],
       [0.7252287231732114, 0.7035006648019607, 0.5232909102450685, 1.0],
       [0.6721006788260085, 0.6908644940528944, 0.48640673089730696, 1.0],
       [0.9368420138138409, 0.8148060186951689, 0.8108391171569428, 1.0],
       [0.8365431136340186, 0.7391903769500965, 0.634340867092744, 1.0]], dtype=object)
TypeError回溯(最近一次调用)
/Users/jespinoz/anaconda/lib/python3.5/site-packages/matplotlib/colors.py in to_rgba(c,alpha)
140试试:
-->141 rgba=_colors_full_map.cache[c,alpha]
142除了(KeyError、TypeError):#不在缓存中或不可损坏。
TypeError:不可损坏的类型:“numpy.ndarray”
在处理上述异常期间,发生了另一个异常:
TypeError回溯(最近一次调用上次)
/Users/jespinoz/anaconda/lib/python3.5/site-packages/matplotlib/colors.py in_to_rgba_no_colorcycle(c,alpha)
191尝试:
-->192 c=元组(map(float,c))
193除类型错误外:
TypeError:只有长度为1的数组才能转换为Python标量
在处理上述异常期间,发生了另一个异常:
ValueError回溯(最近一次调用上次)
在()
13               (0.93684201381384091, 0.81480601869516889, 0.81083911715694279, 1.0),
14(0.83654311363401856,0.73919037695009648,0.63434086709274395,1.0)],数据类型=对象)
--->15 sns.接头批次(x=u,y=v,颜色=c)
/jointplot中的Users/jespinoz/anaconda/lib/python3.5/site-packages/seaborn/distributions.py(x、y、数据、种类、统计函数、颜色、大小、比率、空间、dropna、xlim、ylim、joint_-kws、marginal_-kws、annot_-kws、**kwargs)
789如果颜色为“无”:
790 color=调色板()[0]
-->791 color\u rgb=mpl.colors.colorConverter.to\u rgb(颜色)
792 colors=[在np.linspace(1,0,12)中为l设置值(color\rgb,l=l)]
793 cmap=混合调色板(颜色,如cmap=真)
/Users/jespinoz/anaconda/lib/python3.5/site-packages/matplotlib/colors.py in to_rgb(arg)
307如果*arg*是*RGBA*,那么*A*将被丢弃。
308         """
-->309返回_rgb(arg)
310
311@staticmethod
/Users/jespinoz/anaconda/lib/python3.5/site-packages/matplotlib/colors.py in to_rgb(c)
242“将`c`转换为RGB颜色,无声地删除alpha通道。
243     """
-->244返回_gba(c)[:3]
245
246
/Users/jespinoz/anaconda/lib/python3.5/site-packages/matplotlib/colors.py in to_rgba(c,alpha)
141 rgba=_colors_full_map.cache[c,alpha]
142除了(KeyError、TypeError):#不在缓存中或不可损坏。
-->143 rgba=_至_rgba_无颜色循环(c,alpha)
144尝试:
145 _colors_full_map.cache[c,alpha]=rgba
/Users/jespinoz/anaconda/lib/python3.5/site-packages/matplotlib/colors.py in_to_rgba_no_colorcycle(c,alpha)
192 c=元组(map(float,c))
193除类型错误外:
-->194 raise VALUERROR(“无效的RGBA参数:{!r}.”格式(orig_c))
195如果len(c)不在[3,4]中:
196提升值错误(“RGBA序列的长度应为3或4”)
ValueError:无效的RGBA参数:数组([[0.3899813742681155,0.61096221497505978,0.40096663322878834,1.0],
[0.9181959790338574, 0.7924782609853602, 0.7675461018563338, 1.0],
[0.8069328098220581, 0.7275692815784087, 0.5991742642903236, 1.0],
[0.6721006788260085, 0.6908644940528944, 0.48640673089730696, 1.0],
[0.5759073077002413, 0.668956243661246, 0.43845220910273563, 1.0],
[0.6325231505553612, 0.6819347727880261, 0.4639878928469835, 1.0],
[0.7252287231732114, 0.7035006648019607, 0.5232909102450685, 1.0],
[0.6721006788260085, 0.6908644940528944, 0.48640673089730696, 1.0],
[0.9368420138138409, 0.8148060186951689, 0.8108391171569428, 1.0],
[0.8365431136340186,0.7391903769500965,0.634340867092744,1.0]],数据类型=对象)

一个连接图由边上的边缘图(默认的直方图)和中间的联合图(默认情况下的散点图)组成,在

中您可以阅读更多的内容。

在这种情况下,您想将参数传递给中间的散点图,可以在 SNS.JoopPythTo()/Cl>中使用<代码> JountKWS < /Cl>参数。该参数取一个参数名称字典及其参数,并将其传递给用于创建中间图的函数,在这种情况下<代码> PLT.Stutter()。

c
参数控制颜色,并接受颜色元组列表,因此需要通过
c.tolist()
转换数组。最后一个警告是seaborn已经将颜色传递给
plt.scatter()的
color
参数
,因此我们需要将其设置为
None
,以避免因尝试设置标记颜色两次而引发错误

sns.jointplot(u, v, joint_kws={'color':None, 'c':c.tolist()})