python-3.x - 用户警告:轮廓未使用以下 kwarg:'label'、'color'
问题描述
我试图在我的数据集上使用 Seaborn 的 PairGrid 函数创建一个比较图。我的数据集有 6 列,我试图使用 scatter() 函数在我应用于整个数据帧的 PairGrid 函数的 .map_upper 段中进行绘制。这是我的数据框对象的快速峰值;'year' 对象被设置为数据框的索引
以下是我的数据框 comp_pct_chg_df 的数据类型:
年对象阿姆斯特丹 float64 巴塞罗那 float64 金士顿 float64 米兰 float64 费城 float64 全球 float64 dtype: object
下面是我的错误代码:
# Creating a comparison plot (.PairGrid()) of all my cities' and global data's average percent change in temperature
# Set up my figure by naming it 'pct_chg_yrly_fig', then call PairGrid on the DataFrame
pct_chg_yrly_fig = sns.PairGrid(comp_pct_chg_df.dropna())
# Using map_upper we can specify what the upper triangle will look like.
pct_chg_yrly_fig.map_upper(plt.scatter,color='purple')
# We can also define the lower triangle in the figure, including the plot type (KDE) or the color map (BluePurple)
pct_chg_yrly_fig.map_lower(sns.kdeplot,cmap='cool_d')
# Finally we'll define the diagonal as a series of histogram plots of the yearly average percent change in temperature
pct_chg_yrly_fig.map_diag(plt.hist,histtype='step',linewidth=3,bins=30)
# Adding a legend
pct_chg_yrly_fig.add_legend()
一些可视化确实绘制出来了,比如我使用的 .map_lower() 函数,结果很好。但是,我想为我使用的 .map_upper() 函数中使用的散点图以不同的颜色绘制每个城市。现在它是单色的,很难分辨哪些数据点属于哪个城市。最后,我的 .map_diag() 根本没有绘图。我不知道我做错了什么。我已经评估了收到的 ValueError 消息(如下所示),并尝试专门操作数十个 **kwargs、标签和颜色,但无济于事。帮助将不胜感激。
Here is the ValueError msg I'm receiving:
ValueError Traceback (most recent call last)
<ipython-input-38-3fcf1b69d4ef> in <module>()
11
12 # Finally we'll define the diagonal as a series of histogram plots of the yearly average percent change in temperature
---> 13 pct_chg_yrly_fig.map_diag(plt.hist,histtype='step',linewidth=3,bins=30)
14
15 # Adding a legend
~/anaconda3/lib/python3.6/site-packages/seaborn/axisgrid.py in map_diag(self, func, **kwargs)
1361
1362 if "histtype" in kwargs:
-> 1363 func(vals, color=color, **kwargs)
1364 else:
1365 func(vals, color=color, histtype="barstacked", **kwargs)
~/anaconda3/lib/python3.6/site-packages/matplotlib/pyplot.py in hist(x, bins, range, density, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, stacked, normed, hold, data, **kwargs)
3023 histtype=histtype, align=align, orientation=orientation,
3024 rwidth=rwidth, log=log, color=color, label=label,
-> 3025 stacked=stacked, normed=normed, data=data, **kwargs)
3026 finally:
3027 ax._hold = washold
~/anaconda3/lib/python3.6/site-packages/matplotlib/__init__.py in inner(ax, *args, **kwargs)
1715 warnings.warn(msg % (label_namer, func.__name__),
1716 RuntimeWarning, stacklevel=2)
-> 1717 return func(ax, *args, **kwargs)
1718 pre_doc = inner.__doc__
1719 if pre_doc is None:
~/anaconda3/lib/python3.6/site-packages/matplotlib/axes/_axes.py in hist(***failed resolving arguments***)
6137 color = mcolors.to_rgba_array(color)
6138 if len(color) != nx:
-> 6139 raise ValueError("color kwarg must have one color per dataset")
6140
6141 # If bins are not specified either explicitly or via range,
ValueError: color kwarg must have one color per dataset
我还注意到我的索引,年份对象,在我的 PairGrid 的左上角绘制出来。它看起来像一堆彼此相邻绘制的垂直线。不知道为什么要绘制,但可能是因为值(1743 年 - 2015 年)以“.0”结尾?当我将数据框放在一起时我注意到了这一点(我不知道如何删除它......这里是 Python newb)所以我将年份列的数据类型从 float64 更改为字符串并将其设置为我的索引。我认为这样做会使我的索引“不可行”,这意味着即使值是数字,数据类型设置为字符串,因此无法对它们进行计算?我在这里错过了什么吗?
解决方案
推荐阅读
- c - 我的中断没有更新我的主值,我应该如何设置我的中断?
- python - 无法通过命令行写入文件
- prolog - 是否有正式的系统可以让你做出类似人类的高阶陈述?
- node.js - PostgreSQL 的带有条件过滤的 ILIKE 查询
- python-3.x - 在 json 文件中添加值
- javascript - 在范围上进行双重 for 循环以从列中获取电子邮件并为该电子邮件 (GAS) 撰写表格
- vue.js - 在创建的钩子(vue.js)中模拟 setInterval
- c# - sr.ReadLine() 没有接收到正在发送的数据
- python-3.x - 使用 pyinstaller 编译后 youtube_dl 的导入错误
- regex - 不连续 2 次重复相同字符的正则表达式