jupyter1.用pandas读取data目录下文件employee.csv 2.用读取的数据分别绘制各产业就业人员散点图 3.用读取的数据将三个产业就业人员散点图绘制到一个图上
时间: 2024-04-30 09:22:24 浏览: 49
Python基于pandas绘制散点图矩阵代码实例
```python
import pandas as pd
import matplotlib.pyplot as plt
# 读取employee.csv文件
df = pd.read_csv('data/employee.csv')
# 绘制各产业就业人员散点图
for industry in df['industry'].unique():
sub_df = df[df['industry'] == industry]
plt.scatter(sub_df['salary'], sub_df['experience'], label=industry)
plt.xlabel('Salary')
plt.ylabel('Experience')
plt.title('Employee Distribution by Industry')
plt.legend()
plt.show()
# 将三个产业就业人员散点图绘制到一个图上
fig, ax = plt.subplots()
for industry in df['industry'].unique():
sub_df = df[df['industry'] == industry]
ax.scatter(sub_df['salary'], sub_df['experience'], label=industry)
ax.set_xlabel('Salary')
ax.set_ylabel('Experience')
ax.set_title('Employee Distribution by Industry')
ax.legend()
plt.show()
```
阅读全文