plot 增加不同颜色对应的图标说明
时间: 2024-10-11 10:03:41 浏览: 23
在数据可视化中,`plot()`函数通常用于创建图表,如折线图、散点图等。如果你想在同一个图上增加不同颜色对应的不同图标(标记),可以这样做:
1. **Python (matplotlib)**:
```python
import matplotlib.pyplot as plt
# 数据
data = {'color1': [1, 2, 3], 'color2': [4, 5, 6], 'color3': [7, 8, 9]}
labels = ['A', 'B', 'C']
# 创建图表
fig, ax = plt.subplots()
for key in data:
ax.scatter(data[key][:2], data[key][2:], label=key, c=key) # 使用颜色key作为颜色
ax.legend() # 显示图例
# 设置其他属性,如标题、坐标轴标签
plt.title('不同颜色对应不同图标')
plt.xlabel('X轴')
plt.ylabel('Y轴')
plt.show()
```
2. **Matplotlib with Seaborn** (如果需要更复杂的颜色映射和图标选择):
```python
import seaborn as sns
sns.set_theme(style="darkgrid")
# 使用sns.scatterplot
df = pd.DataFrame({'x': [1, 2, 3], 'y': [4, 5, 6], 'label': ['color1', 'color2', 'color3']})
g = sns.scatterplot(x='x', y='y', hue='label', data=df)
g.legend(title="Colors") # 设置图例标题
# 展示图表
g.figure.show()
```
阅读全文
相关推荐

















