python - 执行图例函数时出现“名称'scatter'未定义”错误
问题描述
执行此程序时出现“散点词未定义错误”
fig, ax= plt.subplots()
ax.scatter(x=data['Odometer (KM)'],
y=data['Price'],
c=data['Doors'])
ax.set(title='Car sales',
xlabel='Odometer',
ylabel='Price')
#legend function
ax.legend(*scatter.legend_elements(), title='Doors');
解决方案
问题是您没有定义实例分散。你为什么不试试这个?
'```
fig, ax= plt.subplots()
scatter = ax.scatter(x=data['Odometer (KM)'], y=data['Price'], c=data['Doors'])
ax.set(title='Car sales', xlabel='Odometer', ylabel='Price')
#legend function
ax.legend(*scatter.legend_elements(), title='Doors');
推荐阅读
- python - median is not working on a list in python
- c++ - 如何将“.bc”库中的符号(即:来自 emar archiver builder 的 .a 后缀)导出到 javascript?
- java - 我的 ViewModel 无法在配置更改后继续存在
- c# - C# / ASP.NET Core 的 ExpressJS 等价物是什么?
- sql-server - 在 varbinary 中设置位
- python-3.x - twilio:检测到拨号目标正忙?
- c++ - 在 Ubuntu 16.04 中设置 libjpeg 环境变量
- c++ - 将 sqlite 数据库中的图像显示到 QTableView 中的列
- java - 如何从存储库类房间数据库中的实时数据中获取值
- java - 安装多个后端映像的 docker 错误